"Open powershell window here" missing terminator

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.

2 Likes

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

image

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

  1. Take/change ownership of HKEY_CLASSES_ROOT\Directory\Background\shell\Powershell\command
  2. Grant change permissions
  3. 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.

  1. THIS MAKES CHANGES TO YOUR REGISTRY! USE AT YOUR OWN RISK!!
  2. This worked for me in ISE, but not in powershell. I have not had time to debug it.
  3. 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 :slight_smile:

3 Likes

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
image

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.

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.