Advertisement
Combreal

runElevatedCheck.ps1

Nov 14th, 2022 (edited)
1,118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #Verifies that the script is running elevated
  2. If (-Not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] 'Administrator')) {
  3.  If ([int](Get-CimInstance -Class Win32_OperatingSystem | Select-Object -ExpandProperty BuildNumber) -ge 6000) {
  4.   $Cx = "-File `"" + $MyInvocation.MyCommand.Path + "`" " + $MyInvocation.UnboundArguments
  5.   Start-Process -FilePath PowerShell.exe -Verb Runas -ArgumentList "-noexit",$Cx
  6.   Exit
  7.  }
  8. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement