Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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