Skip to content

Instantly share code, notes, and snippets.

@r00t-3xp10it
Last active December 9, 2023 01:59
Show Gist options
  • Save r00t-3xp10it/d6048639fd8233cdda30f4dff0498471 to your computer and use it in GitHub Desktop.
Save r00t-3xp10it/d6048639fd8233cdda30f4dff0498471 to your computer and use it in GitHub Desktop.
PS1 AutoElevate Demo Script
# If a script needs to be run elevated, then you can ensure it will only
# ever be run elevated by including the logic within the script.
## Check privileges
If(-not([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator))
{
## Not-ADMIN = Relaunch as an elevated process:
Start-Process powershell.exe "-File",('"{0}"' -f $MyInvocation.MyCommand.Path) -Verb RunAs
exit
}
## Everything that follow the 'Check privileges' ( above ) function
# will be executed with ADMIN privs... the next function its just
# for us to visially check the privileges that we current have ..
## COPY Update-KB303933.PS1 source code here ...
## Check privileges again
$IsClientAdmin = [bool](([System.Security.Principal.WindowsIdentity]::GetCurrent()).groups -Match "S-1-5-32-544")
If($IsClientAdmin -iMatch 'True')
{
Write-host "Administrator" -ForegroundColor Green
Start-Process calc.exe
}
Else
{
Write-host "UserLand" -ForegroundColor red -BackgroundColor Black
Start-Process mspaint.exe
}
Start-Sleep -Seconds 2
@r00t-3xp10it
Copy link
Author

SpoolTrigger

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment