Skip to content

Instantly share code, notes, and snippets.

@aytch
Last active August 24, 2018 16:53
Show Gist options
  • Select an option

  • Save aytch/d11acaa144f7e9cf78044a92fa366e13 to your computer and use it in GitHub Desktop.

Select an option

Save aytch/d11acaa144f7e9cf78044a92fa366e13 to your computer and use it in GitHub Desktop.
function Set-ElevatedStatus {
# If you launched Powershell normally, this will relaunch Powershell as an Admin
$WindowsPrincipal = new-object System.Security.Principal.WindowsPrincipal(`
[System.Security.Principal.WindowsIdentity]::GetCurrent() )
$IsAdmin = $WindowsPrincipal.IsInRole(`
[System.Security.Principal.WindowsBuiltInRole]::Administrator)
if ($IsAdmin -eq $True) {
# No action required
}
else {
Start-Process powershell -Verb runas
exit
}
}
Set-ElevatedStatus
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment