Created
May 13, 2015 13:15
-
-
Save MagicAndi/7d8a680601bbf8ac85e0 to your computer and use it in GitHub Desktop.
PowerShell snippet to run PowerShell code in an elevated (UAC) process. Taken from answers to this StackOverflow question: http://stackoverflow.com/questions/7690994/powershell-running-a-command-as-administrator
This file contains 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
If (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) | |
{ | |
#"No Administrative rights, it will display a popup window asking user for Admin rights" | |
$arguments = "& '" + $myinvocation.mycommand.definition + "'" | |
Start-Process "$psHome\powershell.exe" -Verb runAs -ArgumentList $arguments | |
break | |
} | |
#"After user clicked Yes on the popup, your file will be reopened with Admin rights" | |
#"Put your code here" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment