Elevated Shell?

Written by Arne Tiedemann on Friday June 1, 2018

Somtime you have to verify if your PowerShell session runs with elevated permissions. With this short code you can check it and inform the user or stop the script if elevated permissions are required.

If (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole(`
    [Security.Principal.WindowsBuiltInRole] "Administrator"))
    Write-Warning "You do not have Administrator rights to run this script!`nPlease re-run this script as an Administrator!"