In situations where I need to quickly switch from Powershell to the Windows Explorer, I used to be able to launch Windows Explorer from whatever directory I happened to be in, like this:
PS > explorer .
(This is really just calling C:\Windows\explorer.exe
.)
It worked fine until upgrading to Windows 11. Now it silently fails to do anything.
I've confirmed that, even while using the new Terminal app, the command still works in the Command Prompt. And in pwsh, the explorer
alias is still pointing at C:\Windows\explorer.exe
.
So why is it now broken in Powershell? And is there any work-around?
PS: I have confirmed that the following do not work either:
PS > & explorer . # Nothing
PS > C:\Windows\explorer.exe . # Nada
PS > & C:\Windows\explorer.exe . # Zilch
CodePudding user response:
This is just a workaround, but as you confirmed it working, I'll turn it into an answer:
$shell = New-Object -ComObject Shell.Application
$shell.Open( $PWD.Path )
# Also works:
# $shell.Explore( $PWD.Path )
Create an instance of the Shell
COM object and then call its methods Open
or Explore
to open the current directory, obtained from automatic variable $PWD
, in Explorer.