Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- try {
- $orig_eap = $ErrorActionPreference
- $ErrorActionPreference = 'Stop'
- $wp = [Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()
- if ($wp.IsInRole("Administrators")) {
- # Put commands here for running with Administrator privileges
- }
- else {
- throw "Administrator privilege required. Please run this script with an elevated PowerShell prompt."
- }
- }
- catch {
- Write-Host 'Error:' $Error[0].Exception.Message
- }
- finally {
- $ErrorActionPreference = $orig_eap
- Write-Host ''
- Read-Host '>> Hit Enter key to exit'
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement