Skip to content

Instantly share code, notes, and snippets.

@roelds
Created September 9, 2023 00:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roelds/7e045952ea1736ed69fc92190d21bbbc to your computer and use it in GitHub Desktop.
Save roelds/7e045952ea1736ed69fc92190d21bbbc to your computer and use it in GitHub Desktop.
Require or Verify PowerShell Script Run As Admin
#Requires RunAsAdministrator
# put above comment at top of script to prevent running of script if it was not run as admin
# or quietly check for script run as admin:
([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment