This happens when I open a ps window in a folder with the Shift + r click context menu. Help?
Only when you open using the context menu or does it happen when you just launch ps? in any case iād check your PS profile $profile probably.
Thanks for the response!
Only when I use the context menu. I managed to do what I needed to launching ps. I did the profile thing and it just produced C:\Users.ā¦\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
That folder doesnāt exist. Not sure what I do with this.
I had the same problem. Do you have a solution to fix the problem yet? Please share it, thank you very much
That was just 12h ago, so no solution yet.
Youāre going to have to debug further and provide more info. Does this happen in many folders or just one? Is it a local drive or remote? Is it onedrive? Test, test, and test some more. Then come back and give us more details.
Any folder. Local. Not onedrive. W10.
When you output $Profile, does any part of that path you omitted have a single quote in it, or an apostrophe?
Iāve tried to reproduce whatās happening to you and I cannot.
(Edit 2)-Nope-. (Donāt know how to strikethrough here).
I got the missing profile issue on the brain and am at a different computer atm - that may be the case with the missing terminator. Iāll check when I get home.
I found this concerning the missing profile locationā¦(Edit): And just realized how old it is.
That was the only way I could replicate it.
āOpen PowerShell window hereā throws that error if the path contains an apostrophe.
āOpen in Terminalā doesnāt throw the error, even when the default terminal is changed to Windows PowerShell.
āPowerShell Hereā from Directory Opus also works.
Looks like a problem with the context menu handler. Itās defined as:
powershell.exe -noexit -command Set-Location -literalPath '%V'
If %V is being passed as E:\Temp\Matt's it will fail.
If you check the command in a prompt, it will autocomplete the path as
Set-Location -LiteralPath 'E:\Temp\Matt''s\'
I thought using double quotes around the %V might work (thatās how itās defined for cmd) - but it didnāt.
Context menu handler is defined in HKEY_CLASSES_ROOT\Directory\Background\shell\Powershell\command
if anyone wants to play.
Try this. Go to your C drive, create a Temp directory if it doesnāt already exist. Try to open powershell there. I find it more than hard to believe itās āany folder.ā
Good work Matt. What I found to fix this was to set it to
powershell.exe -noexit -command Set-Location -literalPath """%V"""
With that set, now I can use folders with the single quote

To change this setting, the first thing you have to do is grant yourself permissions to change it. The key is owned by TrustedInstaller. So the steps would be something like
- Take/change ownership of
HKEY_CLASSES_ROOT\Directory\Background\shell\Powershell\command - Grant change permissions
- Edit the default reg_sz entry as shown above
Iāve written a script to automate the changing ownership to Administrators, changing permissions, and setting the registry value. You can find the script here
A couple of things to note.
- THIS MAKES CHANGES TO YOUR REGISTRY! USE AT YOUR OWN RISK!!
This worked for me in ISE, but not in powershell. I have not had time to debug it.I have not found a way to programmatically set the owner back to TrustedInstaller.
To change the owner manually, go into the permissions in regedit, change owner, and type in NT Service\TrustedInstaller as the username.
EDIT I figured out the issue, the script works now.
EDIT 2 Ok I sorted out setting the owner back. Iāve updated the script to where it will change owner to administrators (of the command registry key,) set Administrators to FullControl, make the change to the registry value, set the Administrators permissions back to ReadKey, and finally set TrustedInstaller back as the owner. This was fun ![]()
FYI, this may have fixed it for some paths but not others.
Alright, hereās what Iāve found out. I noticed that being in the folder and right clicking vs clicking the folder itself are handled by different registry entries.
In the folder, itās the key Matt pointed out
Right clicking the folder itself is handled by HKEY_CLASSES_ROOT\Directory\shell\Powershell\command

I updated my script to change both of those. I also liked the look of \"%V\" better than """%V""" and it works the same as far as my tests have shown.

