3

I use very frequently the trick of putting cmd or powershell in the file explorer location to start a new console at the same path as the file explorer.

However, I cannot start PowerShell with that trick anymore. When I try to input powershell, it open the following directory instead of opening a console : C:\Users\{username}\Documents\PowerShell.

Deleting the PowerShell folder "fixes" the issue. My guess is that, by default, if a folder in Documents has the same name as what you type in the location bar, it will open that folder.

So my question is : how can I disable this behavior ? So that I can have a PowerShell folder in Documents and still launch PowerShell from the location bar.

5
  • it works on my end. Which OS version are you on?
    – LPChip
    Commented Jan 14, 2022 at 8:07
  • I am using Windows 10 Enterprise (OS build 19042.1415) right now.
    – Nathan
    Commented Jan 14, 2022 at 8:29
  • Works for me also. Try it when booting in Safe Mode. If this still happens, and as you're using Windows 10 version 20H2, you should upgrade to 21H2 (which you should do anyway). (Add to your comment @harrymc for me to be notified.)
    – harrymc
    Commented Jan 14, 2022 at 9:41
  • Not an answer to your question, but it isn't too hard to create a shortcut that will open powershell pointed at the "current directory". Just create a regular shortcut, edit it, and blank out the target directory, Then just put this short cut in the target directory, navigate to that folder with explorer, and use the shortcut. Commented Jan 14, 2022 at 23:01
  • @harrymc It's not linked to safe mode or the windows version. Actually, deleting the C:\Users\{username}\Documents\PowerShell folder actually "solve" the issue. However it is bothering to no be able to have user specific PowerShell module at this location.
    – Nathan
    Commented Jan 17, 2022 at 9:55

3 Answers 3

4

It seems that the folder C:\Users\{username}\Documents\PowerShell is in your PATH.

This explains why typing powershell opens the folder rather than the program.

If you want to keep on using powershell this way, you may either:

  • Type instead : powershell.exe
  • Remove C:\Users\{username}\Documents from your PATH.
1
  • Indeed powershell.exe works well. Removing Documents from the PATH too. Nice answer !
    – Nathan
    Commented Jan 17, 2022 at 13:04
0

You can get a context menu (right click menu) entry that will open a powershell console at the location that was right clicked.

  1. Open regedit
  2. Navigate to: HKEY_CLASSES_ROOT\Directory\shell
  3. Right-click the shell key and choose New > Key. Name the new key openpowershellhere. You can call it what you want, but not Powershell because that key name already exists.
  4. With the openpowershellhere key selected, double-click the (Default) value to open its properties window.
  5. Set the value in the “Value data” box to Open PowerShell Here
  6. OPTIONAL step to make it so that to option only appears if you hold Shift down while right-clicking (the same way that the “Open Command Prompt” command is hidden unless you Shift+right-click a folder):
    • Right-click the openpowershellhere key and choose New > String Value.
    • Name the new value Extended. You don’t need to make any changes to it. Just having that string there will cause the command to be hidden behind Shift key access.
  7. Next we need to create a new key inside your openpowershellhere key. Right-click the openpowershellhere key and choose New > Key. Name the new key command.
  8. With the command key selected, double-click the (Default) value to open its properties window.
  9. Type the following text into the “Value data” box and then click OK: C:\\Windows\\system32\\WindowsPowerShell\\v1.0\\powershell.exe -NoExit -Command Set-Location -LiteralPath '%L'

The changes should take place immediately, so you can exit out of Registry Editor. To test it out, just right-click (or Shift+right-click if you set up that option) any folder and make choose the ”Open with PowerShell” command.

2
  • Hello, thanks for you answer. I can already have this context menu using shift + right click. This is indeed quite practical. However this is not what I'm looking for. I would like to understand why the explorer location bar method is no longer working for me.
    – Nathan
    Commented Jan 17, 2022 at 9:06
  • ok, so the real issue was that your PATH variable had the powershell folder in it which screwed up how the location bar in explorer decided what to do when powershell was typed in... makes sense... glad you sorted it out Commented Jan 18, 2022 at 22:01
0

Quick and simple way to start PowerShell via Windows terminal

Type wt into address bar of file explorer to open Windows terminal.

Windows terminal can be set to start as PowerShell 1.0 (basic version that comes with Windows) but also newest PowerShell 7++, git bash, cmd, etc.

For me It's faster to write wt instead of powershell.exe and it doesn't matter if there's PS folder in my documents.

To start Windows terminal at current directory use wt -d .

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .