Check script has been run with administration rights in PowerShell

Check PowerShell script has been run with administration rights…

# Check if the script has been run with Admin Privilages
function Test-Administrator
{
$user = [Security.Principal.WindowsIdentity]::GetCurrent();
(New-Object Security.Principal.WindowsPrincipal $user).IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
}

Leave a Reply

Your email address will not be published. Required fields are marked *

fifteen − 14 =