Detect elevated privileges
Sometimes you get a requirement to start a Powershell script from an elevated prompt. Here is a quick function to check that :
function Test-ElevatedPrompt { [Security.Principal.WindowsPrincipal] $Identity = [Security.Principal.WindowsIdentity]::GetCurrent() $Identity.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator) }
This will return a simple boolean so you can use it this way :