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

Working with Registry Keys
Powershell.com Chaprter 16 Registry

Categories: Powershell


Aleksandar · December 20, 2011 at 3:26 pm

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

    C-Rad · December 20, 2011 at 4:31 pm

    That’s great! Thanks for the Tip!

winter · December 20, 2011 at 4:30 pm

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

    C-Rad · December 20, 2011 at 4:36 pm

    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