-
-
Save sdovnic/e0121316734049e59ef3 to your computer and use it in GitHub Desktop.
A self-elevating powershell script.
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
if (([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) | |
{ | |
"Running as admin in $PSScriptRoot" | |
} | |
else | |
{ | |
"NOT running as an admin!" | |
Start-Process powershell -WorkingDirectory $PSScriptRoot -Verb runAs -ArgumentList "-noprofile -noexit -file $PSCommandPath" | |
return "Script re-started with admin privileges in another shell. This one will now exit." | |
} | |
"Doing this only as admin." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Smaller but not so cleaner: