Created
June 16, 2014 03:39
-
-
Save ebibibi/2cf0f4206e94b917e4f1 to your computer and use it in GitHub Desktop.
run as administrator in PowerShell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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