Advertisement
Combreal

PS-uac.ps1

Jun 16th, 2024 (edited)
805
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Function Test-Admin {
  2.     $currentUser = New-Object Security.Principal.WindowsPrincipal $([Security.Principal.WindowsIdentity]::GetCurrent())
  3.     $currentUser.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
  4. }
  5.  
  6. If((Test-Admin) -eq $false)  {
  7.     Start-Process powershell.exe -Verb RunAs -ArgumentList ('-noprofile -noexit -file "{0}" -elevated' -f ($myinvocation.MyCommand.Definition))
  8.     Exit
  9. }
  10.  
  11. #The following will run as Adminstrator
  12. Write-Host "Ran as Admin"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement