How can I tell in my scripts if PowerShell is running with administrator privileges?
I need to know because I'm trying to run a program that requires the ability to open protected ports.
powershell
How can I tell in my scripts if PowerShell is running with administrator privileges?
I need to know because I'm trying to run a program that requires the ability to open protected ports.
Best Answer
Breaking apart what this does:
[bool]
- Cast the end result to abool
.[System.Security.Principal.WindowsIdentity]::GetCurrent()
- Retrieves theWindowsIdentity
for the currently running user.(...).groups
- Access thegroups
property of the identity to find out what user groups the identity is a member of.-match "S-1-5-32-544"
checks to see ifgroups
contains the Well Known SID of the Administrators group, the identity will only contain it if "run as administrator" was used.