Created
July 3, 2020 09:34
-
-
Save theTonyHo/fac6eccf2fcfb8118b0533db3ed2f3fe to your computer and use it in GitHub Desktop.
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
# Reference: https://ss64.com/ps/syntax-elevate.html | |
# Place this in beginning of script | |
If (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) | |
{ | |
# Relaunch as an elevated process: | |
Write-Host "Executing Script as Administrator" -ForegroundColor Green | |
Start-Process powershell.exe "-File",('"{0}"' -f $MyInvocation.MyCommand.Path) -Verb RunAs | |
exit | |
} | |
Write-Host "Executing script" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment