Skip to content

Instantly share code, notes, and snippets.

@SweetAsNZ
Created February 7, 2022 03:00
Show Gist options
  • Select an option

  • Save SweetAsNZ/59634f007a38c1725fab27ae5d56ac31 to your computer and use it in GitHub Desktop.

Select an option

Save SweetAsNZ/59634f007a38c1725fab27ae5d56ac31 to your computer and use it in GitHub Desktop.
Find out if the current user identity is elevated (has admin rights)
function Get-IfImAdmin{
# Find out if the current user identity is elevated (has admin rights)
$identity = [Security.Principal.WindowsIdentity]::GetCurrent()
$identity
$principal = New-Object Security.Principal.WindowsPrincipal $identity
$principal
$isAdmin = $principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
Write-Output ""
Write-Output "Using:" (Get-Identity).AuthenticationType
Write-Output ""
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment