Skip to content

Instantly share code, notes, and snippets.

@ismits
Created May 1, 2019 19:40
Show Gist options
  • Save ismits/ad1a5f76975448a945c0893655882486 to your computer and use it in GitHub Desktop.
Save ismits/ad1a5f76975448a945c0893655882486 to your computer and use it in GitHub Desktop.
PowerShell function to test whether the current script is running as an elevated admin
function Is-Elevated
{
$wid = [System.Security.Principal.WindowsIdentity]::GetCurrent()
$prp = New-Object System.Security.Principal.WindowsPrincipal($wid)
$adm = [System.Security.Principal.WindowsBuiltInRole]::Administrator
$IsAdmin = $prp.IsInRole($adm)
return $IsAdmin
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment