Skip to content

Instantly share code, notes, and snippets.

@h3nryza
Created July 17, 2018 17:28
Show Gist options
  • Select an option

  • Save h3nryza/576371e75dbc9dfcaeda800ed9134d2b to your computer and use it in GitHub Desktop.

Select an option

Save h3nryza/576371e75dbc9dfcaeda800ed9134d2b to your computer and use it in GitHub Desktop.
Powershell AutoElevate a script
#Elevate to Admin
if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs; exit }
#Your code here
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment