Check for elevation in PowerShell

Check if PowerShell is elevated.

John Savill

March 28, 2017

1 Min Read
Check for elevation in PowerShell

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."}

 

About the Author

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.

You May Also Like