Created
February 7, 2022 03:00
-
-
Save SweetAsNZ/59634f007a38c1725fab27ae5d56ac31 to your computer and use it in GitHub Desktop.
Find out if the current user identity is elevated (has admin rights)
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
| 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