Skip to content

Instantly share code, notes, and snippets.

@ebibibi
Created June 16, 2014 03:39
Show Gist options
  • Select an option

  • Save ebibibi/2cf0f4206e94b917e4f1 to your computer and use it in GitHub Desktop.

Select an option

Save ebibibi/2cf0f4206e94b917e4f1 to your computer and use it in GitHub Desktop.
run as administrator in PowerShell
Param
(
[String]$Path = (Get-Location)
)
# Elevate
Write-Host "Checking for elevation... " -NoNewline
$CurrentUser = New-Object Security.Principal.WindowsPrincipal $([Security.Principal.WindowsIdentity]::GetCurrent())
if (($CurrentUser.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)) -eq $false) {
ArgumentList = "-noprofile -noexit -file `"{0}`" -Path `"$Path`""
If ($ValidateOnly) {$ArgumentList = $ArgumentList + " -ValidateOnly"}
If ($SkipValidation) {$ArgumentList = $ArgumentList + " -SkipValidation $SkipValidation"}
Write-Host "elevating"
Start-Process powershell.exe -Verb RunAs -ArgumentList ($ArgumentList -f ($myinvocation.MyCommand.Definition))
Exit
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment