Wednesday, May 3, 2017

Is the current user a local admin?

If (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole(`
    [Security.Principal.WindowsBuiltInRole] “Administrator”))
{
    Write-Warning “<ERROR MESSAGE GOES HERE>”
    Break
}

No comments:

Post a Comment