Advertisement
Guest User

Untitled

a guest
Aug 18th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. try {
  2. $orig_eap = $ErrorActionPreference
  3. $ErrorActionPreference = 'Stop'
  4.  
  5. $wp = [Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()
  6. if ($wp.IsInRole("Administrators")) {
  7. # Put commands here for running with Administrator privileges
  8. }
  9. else {
  10. throw "Administrator privilege required. Please run this script with an elevated PowerShell prompt."
  11. }
  12. }
  13. catch {
  14. Write-Host 'Error:' $Error[0].Exception.Message
  15. }
  16. finally {
  17. $ErrorActionPreference = $orig_eap
  18.  
  19. Write-Host ''
  20. Read-Host '>> Hit Enter key to exit'
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement