Skip to content

Instantly share code, notes, and snippets.

@oledid
Last active August 18, 2017 21:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oledid/688d83ffdd45346e9bdf to your computer and use it in GitHub Desktop.
Save oledid/688d83ffdd45346e9bdf to your computer and use it in GitHub Desktop.
PowerShell: Run script as administrator
If (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator"))
{
$arguments = "& '" + $myinvocation.mycommand.definition + "'"
Start-Process powershell -Verb runAs -ArgumentList $arguments
Break
}
Set-Location $PSScriptRoot
# do stuff
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment