Skip to content

Instantly share code, notes, and snippets.

@jbratu
Created March 24, 2022 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbratu/d5e5939b4e2ec2fe9c4f894fe911f36b to your computer and use it in GitHub Desktop.
Save jbratu/d5e5939b4e2ec2fe9c4f894fe911f36b to your computer and use it in GitHub Desktop.
elevate powershell script
#https://blog.expta.com/2017/03/how-to-self-elevate-powershell-script.html
# Self-elevate the script if required
if (-Not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] 'Administrator')) {
if ([int](Get-CimInstance -Class Win32_OperatingSystem | Select-Object -ExpandProperty BuildNumber) -ge 6000) {
$CommandLine = "-File `"" + $MyInvocation.MyCommand.Path + "`" " + $MyInvocation.UnboundArguments
Start-Process -FilePath PowerShell.exe -Verb Runas -ArgumentList $CommandLine
Exit
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment