wthiel / Elevated Powershell Example

0 лайк(-ов)
0 форк(-ов)
1 файл(-ов)
Последняя активность 7 months ago
This script ensures that it runs with administrator privileges before executing the actual code. If no admin rights are available, it restarts itself with elevated privileges.
1 param([switch]$Elevated)
2
3 function Test-Admin {
4 $currentUser = New-Object Security.Principal.WindowsPrincipal $([Security.Principal.WindowsIdentity]::GetCurrent())
5 $currentUser.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
6 }
7
8 if ((Test-Admin) -eq $false) {
9 if ($elevated) {
10 # tried to elevate, did not work, aborting
Новее Позже