Created
August 14, 2020 19:11
-
-
Save BanterBoy/1bd2b984ecbbb2b0138859db02748b85 to your computer and use it in GitHub Desktop.
Function to test if the current session is running as an administrator
This file contains 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
function Test-IsAdmin { | |
<# | |
.Synopsis | |
Tests if the user is an administrator | |
.Description | |
Returns true if a user is an administrator, false if the user is not an administrator | |
.Example | |
Test-IsAdmin | |
#> | |
$identity = [Security.Principal.WindowsIdentity]::GetCurrent() | |
$principal = New-Object Security.Principal.WindowsPrincipal $identity | |
$principal.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment