Last active
March 13, 2018 00:20
-
-
Save Jaykul/f2abefe8530cbca72296697bdc2b329e to your computer and use it in GitHub Desktop.
What's the simplest way to test if we're currently running "As Administrator"?
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
#.Synopsis | |
# Returns TRUE if the current PowerShell is running elevated, FALSE otherwise. | |
[CmdletBinding()]param() | |
$IsElevated = ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator) | |
if($IsElevated -ne ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole("Administrators")) { | |
Write-Warning "String Method does not work" | |
} | |
if($IsElevated -ne [Bool]([Security.Principal.WindowsIdentity]::GetCurrent().Groups -eq "S-1-5-32-544")) { | |
Write-Warning "Group SID does not work" | |
} | |
if($IsElevated -ne ([Security.Principal.WindowsIdentity]::GetCurrent().Owner -eq 'S-1-5-32-544')) { | |
Write-Warning "Current.Owner does not work" | |
} | |
return $IsElevated |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment