Last active
April 15, 2019 09:24
-
-
Save zblesk/c169a3cdac4d0e9c118f to your computer and use it in GitHub Desktop.
A self-elevating powershell script. Makes sure current script is running as admin.
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 (([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) | |
{ | |
Set-Location $PSScriptRoot | |
"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