Skip to content

Instantly share code, notes, and snippets.

@adamz01h
Created October 15, 2024 11:17
Show Gist options
  • Select an option

  • Save adamz01h/2f2fd78a5f853786768ff1ac6707f9d5 to your computer and use it in GitHub Desktop.

Select an option

Save adamz01h/2f2fd78a5f853786768ff1ac6707f9d5 to your computer and use it in GitHub Desktop.
auto elevate powershell
#Run as administrator and stays in the current directory
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) {
Start-Process PowerShell -Verb RunAs -ArgumentList "-NoProfile -ExecutionPolicy Bypass -Command `"cd '$pwd'; & '$PSCommandPath';`"";
Exit;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment