-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Milestone
Description
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 Greencode: Load dynamic variables
Metadata
Metadata
Assignees
Labels
No labels
Projects
Status
Published