Last active
June 14, 2019 13:19
-
-
Save cahilfoley/175b14fb08c50bb283a7748c423ebe96 to your computer and use it in GitHub Desktop.
[Powershell] Usefully scripts when working with Powershell #powershell #admin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
######################################################### | |
# Ensure PS script is running with elevated permissions # | |
######################################################### | |
# Works in Powershell >= v4.0, add to top of file | |
#Requires -RunAsAdministrator | |
# Works in all versions of powershell, add to top of file | |
If (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { | |
Write-Output "This script needs to be run As Admin" | |
Break | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment