Created
March 23, 2018 11:15
-
-
Save YakDriver/2c584a44b5b7be9ba8ae526d2243909a to your computer and use it in GitHub Desktop.
Is PowerShell script running as administrator? Find out from inside the script.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Get the ID and security principal of the current user account | |
$myWindowsID=[System.Security.Principal.WindowsIdentity]::GetCurrent() | |
$myWindowsPrincipal=new-object System.Security.Principal.WindowsPrincipal($myWindowsID) | |
# Get the security principal for the Administrator role | |
$adminRole=[System.Security.Principal.WindowsBuiltInRole]::Administrator | |
# Check to see if we are currently running "as Administrator" | |
if ($myWindowsPrincipal.IsInRole($adminRole)) | |
{ | |
Write-Host "Running as Administrator" | |
} | |
else | |
{ | |
Write-Host "NOT Running as Administrator" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment