Skip to content

Instantly share code, notes, and snippets.

@BanterBoy
Created August 14, 2020 19:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BanterBoy/1bd2b984ecbbb2b0138859db02748b85 to your computer and use it in GitHub Desktop.
Save BanterBoy/1bd2b984ecbbb2b0138859db02748b85 to your computer and use it in GitHub Desktop.
Function to test if the current session is running as an administrator
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