Created
April 30, 2018 08:36
-
-
Save yoav-lavi/463031d18348f5edac7867538bf2b50c to your computer and use it in GitHub Desktop.
Elevation function for PowerShell scripts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Elevate { | |
Param ($Path) | |
if (-Not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] 'Administrator') ` | |
-And [int](Get-CimInstance -Class Win32_OperatingSystem | Select-Object -ExpandProperty BuildNumber) -ge 6000) | |
{ | |
$CommandLine = "-File `"$Path`"" | |
Start-Process -FilePath PowerShell.exe -Verb Runas -ArgumentList $CommandLine | |
Exit | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment