Skip to content

Instantly share code, notes, and snippets.

@cheshirecode
Created April 28, 2017 02:35
Show Gist options
  • Save cheshirecode/21a51e163a150159aea88c142a64826d to your computer and use it in GitHub Desktop.
Save cheshirecode/21a51e163a150159aea88c142a64826d to your computer and use it in GitHub Desktop.
Add context menu item to start an elevated PowerShell from Windows Explorer
$menu = 'Open Windows PowerShell Here as Administrator'
$command = "$PSHOME\powershell.exe -NoExit -NoProfile -Command ""Set-Location '%V'"""
'directory', 'directory\background', 'drive' | ForEach-Object {
New-Item -Path "Registry::HKEY_CLASSES_ROOT\$_\shell" -Name runas\command -Force |
Set-ItemProperty -Name '(default)' -Value $command -PassThru |
Set-ItemProperty -Path {$_.PSParentPath} -Name '(default)' -Value $menu -PassThru |
Set-ItemProperty -Name HasLUAShield -Value ''
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment