Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.
Check if PowerShell is elevated.
March 28, 2017
Q. How can I check if my PowerShell session is elevated using Security.Principal.WindowsIdentity?
A. To easily check for elevation use the following PowerShell snippet of code:
if ((New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)){ Write-Output "Elevated."}else{ Write-Output "Not elevated."}
You May Also Like