Created
June 18, 2022 03:50
-
-
Save sheepla/37f39e8411ba73d3acd737c5290f41b4 to your computer and use it in GitHub Desktop.
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
| <# | |
| .DESCRIPTION | |
| If current user has administrator privilege, returns true else returs false. | |
| .EXAMPLE | |
| Test-DoIHaveAdministratorPrivilege.ps1 | |
| True | |
| #> | |
| $me = [System.Security.Principal.WindowsIdentity]::GetCurrent() -as [System.Security.Principal.WindowsPrincipal] | |
| $admin = [System.Security.Principal.WindowsBuiltInRole]::Administrator | |
| $me.IsInrole($admin) | Write-Output |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Description
System.Security.Principal: Defines a principal object that represents the security context under which code is running. For more information, see Role-Based Security.WindowsIdentify: Represents a Windows user. You can get current user withGetCurrent().WindowsBuiltInRole: Specifies common Windows account roles.IsInRole(): Determines whether the current principal belongs to a specified Windows user group.