Last active
November 21, 2015 21:44
-
-
Save jamesmanning/b27aaac4910c170ab104 to your computer and use it in GitHub Desktop.
Create the registry keys necessary to get 'Open PowerShell here' in Windows Explorer context menus
This file contains hidden or 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
Set-StrictMode -Version Latest | |
# since this won't work without running with admin privs, check for those first | |
$wid=[System.Security.Principal.WindowsIdentity]::GetCurrent() | |
$prp=new-object System.Security.Principal.WindowsPrincipal($wid) | |
$adm=[System.Security.Principal.WindowsBuiltInRole]::Administrator | |
$IsAdmin=$prp.IsInRole($adm) | |
if ($IsAdmin -eq $false) | |
{ | |
throw 'this must be run from an elevated PowerShell instance' | |
} | |
$commandToSet = (gcm powershell).path + " -NoExit -Command Set-Location -LiteralPath '%V'" | |
$keyLocationsToSet = ( | |
'HKEY_CLASSES_ROOT\Directory\Background\shell\powershell', # this puts it in the context menu for Windows Explorer background | |
'HKEY_CLASSES_ROOT\Directory\shell\powershell', # this puts it in the context menu for Windows Explorer folders | |
'HKEY_CLASSES_ROOT\Drive\shell\powershell' # this puts it in the context menu for Windows Explorer drive icons | |
) | |
foreach ($key in $keyLocationsToSet) | |
{ | |
write-host "Setting command to run of $commandToSet in location $key" | |
reg.exe add $key /f /ve /d "Open PowerShell Window Here" | |
reg.exe add $key /f /v NoWorkingDirectory | |
reg.exe add "$key\command" /f /ve /d $commandToSet | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment