cahilfoley
6/17/2018 - 3:59 AM

Ensure PS script is running with elevated permissions

Ensure PS script is running with elevated permissions

# Works in Powershell >= v4.0, add to top of file
#Requires -RunAsAdministrator
# Works in all versions of powershell, add to top of file
If (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {    
    Write-Output "This script needs to be run As Admin"
    Break
}