Skip to content

Instantly share code, notes, and snippets.

@eizedev
Created October 9, 2020 09:32
Show Gist options
  • Save eizedev/b6c2545505389b0b3cac79d8e37e07b1 to your computer and use it in GitHub Desktop.
Save eizedev/b6c2545505389b0b3cac79d8e37e07b1 to your computer and use it in GitHub Desktop.
One-Liner to run the current script elevated as administrator if not already run as admin. Just copy&paste this oneliner to the top of your scripts.
if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs -Wait }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment