Guest User

Untitled

a guest
Oct 23rd, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. Start-Process powershell -verb runas -ArgumentList "-file fullpathofthescript"
  2.  
  3. param([switch]$Elevated)
  4.  
  5. function Test-Admin {
  6. $currentUser = New-Object Security.Principal.WindowsPrincipal $([Security.Principal.WindowsIdentity]::GetCurrent())
  7. $currentUser.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
  8. }
  9.  
  10. if ((Test-Admin) -eq $false) {
  11. if ($elevated)
  12. {
  13. # tried to elevate, did not work, aborting
  14. }
  15. else {
  16. Start-Process powershell.exe -Verb RunAs -ArgumentList ('-noprofile -noexit -file "{0}" -elevated' -f ($myinvocation.MyCommand.Definition))
  17. }
  18.  
  19. exit
  20. }
  21.  
  22. 'running with full privileges'
  23.  
  24. $currentUser = New-Object Security.Principal.WindowsPrincipal $([Security.Principal.WindowsIdentity]::GetCurrent())
  25. $testadmin = $currentUser.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
  26. if ($testadmin -eq $false) {
  27. Start-Process powershell.exe -Verb RunAs -ArgumentList ('-noprofile -noexit -file "{0}" -elevated' -f ($myinvocation.MyCommand.Definition))
  28. exit $LASTEXITCODE
  29. }
Add Comment
Please, Sign In to add comment