Create Open Powershell Here Context Menu Entry with Powershell

I saw this great post a few days ago about adding a  Open Powershell context menu entry using regedit. I thought it was really cool, but quickly decided why not create it using POWERSHELL!!!

I should note, you need to have powershell running as an admin for this…


New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT

new-item -path HKCR:directory/shell/powershell
new-item -path HKCR:directory/shell/powershell/command
set-item -path HKCR:directory/shell/powershell -value "Open PowerShell Here"
set-item -path HKCR:directory/shell/powershell/command -value "C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe -NoExit -Command Set-Location -LiteralPath '%L'"

Here is what it looks like when it is all said and done
This is was also great for me but I am still learning powershell, especially the registry stuff, so it was just good practice for a quick script.
And if you haven’t checked out the original post
Add Open Powershell to Context Menu

References:
Working with Registry Keys
Powershell.com Chaprter 16 Registry

4 Responses to Create Open Powershell Here Context Menu Entry with Powershell

  1. Aleksandar says:

    You can omit line 3 (new-item -path HKCR:directory/shell/powershell) if you use -Force switch in line 4:

    new-item -path HKCR:directory/shell/powershell/command -force

  2. winter says:

    what would be cooler is a context to ‘run script XYZ at this location’

    • C-Rad says:

      That would be cool. I believe it would be easy enough to do as well. If you do a “C:WindowsSystem32WindowsPowerShellv1.0powershell.exe C:script.ps1″ I believe that would do it. Haven’t tested it myself but that is exactly how I have a few scheduled tasks setup on some servers.

Leave a reply