Explorer in Explorer Mode

I tend to fire up Windows Explorer instances from my prompt very often, either on the current directory or in other spots. I was pretty used to using the “explorer /e,<path>” command from CMD.EXE but I never had figured out exactly how to use it on PowerShell and have it work reliably: Paths with spaces always caused it to open the default documents folder instead.

Finally sat down and played with it until I got it right:

# open explorer in this directory
function exp([string] $loc = '.') {
   explorer "/e,"$loc""
}

Comments (5)

JamesOctober 12th, 2008 at 8:35 am

Try ‘invoke-item -path .’ or ‘ii .’
James

Hal RottenbergOctober 12th, 2008 at 3:24 pm

If James hadn’t said that I was going to. :)

Tomas RestrepoOctober 13th, 2008 at 6:29 am

Thanks guys! Yes, it occurred to me later on that I could just "execute" the path and get the right behavior, but, to be honest, getting the right explorer parameters was a challenge I wanted to get done :) (I’m still not 100% sure why the above works while "/e,`"$loc`"" didn’t).

Jason ArcherOctober 13th, 2008 at 10:21 am

Never have used that command, thanks for sharing (I always used "start ."). Strangely enough, both these commands worked without errors:
$loc = "."
explorer "/e,"$loc""
explorer "/e,`"$loc`""

Tomas RestrepoOctober 13th, 2008 at 11:00 am

Jason: Yes, that works for me if $loc doesn’t have spaces in it. That’s when it breaks for me.

Leave a comment

Your comment