Skip to content

Instantly share code, notes, and snippets.

@yangyer
Last active January 30, 2016 00:18
Show Gist options
  • Save yangyer/f857776b40f317fd72ac to your computer and use it in GitHub Desktop.
Save yangyer/f857776b40f317fd72ac to your computer and use it in GitHub Desktop.
Powershell sudo
function Start-ElevatedUACSession {
$outputFiles = @{
Standard = [System.IO.Path]::GetTempFileName();
Error = [System.IO.Path]::GetTempFileName();
}
$cmd = [string]::Join(" ", $args)
Write-Host "Executing Elevated: $cmd"
Start-Process powershell -Verb "runAs" -WindowStyle Hidden -Wait -ArgumentList "/Command ""& { $cmd > '$($outputFiles.Standard)' }"""
Get-Content $outputFiles.Standard
$outputFiles.Values | Remove-Item
}
Set-Alias sudo Start-ElevatedUACSession
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment