Skip to content

Instantly share code, notes, and snippets.

@RaccoonDev
Created March 20, 2016 18:09
Show Gist options
  • Save RaccoonDev/e683d9f839b7f8189fd2 to your computer and use it in GitHub Desktop.
Save RaccoonDev/e683d9f839b7f8189fd2 to your computer and use it in GitHub Desktop.
function EnsureAdminPrivileges([String]$mesageOnError)
{
$identity = [Security.Principal.WindowsIdentity]::GetCurrent()
$principal = new-object Security.Principal.WindowsPrincipal $identity
if (!($principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)))
{
Write-Error $mesageOnError
throw
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment