Skip to content

Setup PowerShell Profiles #103

@asktechsupport

Description

@asktechsupport

See first comment.
Features:

  • Check if you are an admin
  • Load dynamic variables
  • Sync your ISE and PowerShell Profiles
code: Check if you are an admin

#------------------------------------------------------------------------------------------------------------------------------------------------#
#### Function to check if running as administrator
#------------------------------------------------------------------------------------------------------------------------------------------------#
Unblock-File -Path "C:\Windows\System32\WindowsPowerShell\v1.0\Microsoft.PowerShellISE_profile.ps1"
function Test-IsAdmin {
   $currentUser = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
   return $currentUser.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
}
$ErrorActionPreference = "SilentlyContinue"
# Check if running as administrator
if (-not (Test-IsAdmin)) {
   Write-Host "This script must be run as an administrator." -ForegroundColor Red
   Read-Host "Press Enter to close this PowerShell window"    # Wait for user input before closing
   # Close the PowerShell application
   Stop-Process -Id $PID -Force
}
$ErrorActionPreference = "Continue"
Write-Host "Running with administrative privileges." -ForegroundColor Green

code: Load dynamic variables

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    Status

    Published

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions