Got several times script running failed due to the ISE or PowerShell didn’t run as Administrator. Uhmm, trying to show it as log or debug warning for this…
In order to make sure we are running the script as Administrator, we can use following script to test whether we are going to run this or not:
# Get the ID and security principal of the current user account
# Get the security principal for the Administrator role
# Check to see if we are currently running "as Administrator"
$global:AdminPriviledges = $true
# We are not running "as Administrator"
# Exit from the current, unelevated, process
throw "You must run this script as administrator"