Skip to content

Instantly share code, notes, and snippets.

@aytch
Created September 13, 2018 02:01
Show Gist options
  • Select an option

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

Select an option

Save aytch/308fc0452184e3e0c1c9ceec19cc1d7f to your computer and use it in GitHub Desktop.
function Set-ElevatedStatus {
$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