411

I'm sure this must be possible, but I can't find out how to do it.

Any clues?

Carson
  • 6,105
  • 2
  • 37
  • 45
Lachmania
  • 4,613
  • 2
  • 20
  • 15

13 Answers13

863

Use:

ii .

which is short for

Invoke-Item .

It is one of the most common things I type at the PowerShell command line.

Geert Smelt
  • 987
  • 1
  • 7
  • 19
EBGreen
  • 36,735
  • 12
  • 65
  • 85
180

You have a few options:

Examples:

PS C:\> explorer
PS C:\> explorer .
PS C:\> explorer /n
PS C:\> Invoke-Item c:\path\
PS C:\> ii c:\path\
PS C:\> Invoke-Item c:\windows\explorer.exe
PS C:\> ii c:\windows\explorer.exe
PS C:\> [diagnostics.process]::start("explorer.exe")
Bakudan
  • 19,134
  • 9
  • 53
  • 73
codeape
  • 97,830
  • 24
  • 159
  • 188
64

Use any of these:

  1. start .
  2. explorer .
  3. start explorer .
  4. ii .
  5. invoke-item .

You may apply any of these commands in PowerShell.

Just in case you want to open the explorer from the command prompt, the last two commands don't work, and the first three work fine.

20B2
  • 2,011
  • 17
  • 30
34

Just use the Invoke-Item cmdlet. For example, if you want to open a explorer window on the current directory you can do:

Invoke-Item .
Geert Smelt
  • 987
  • 1
  • 7
  • 19
tomasr
  • 13,683
  • 3
  • 38
  • 30
30
explorer .
Daniel Kreiseder
  • 12,135
  • 9
  • 38
  • 59
  • This is what I've been using for years, but recently `explorer` seems to be out my path – DaveD Apr 20 '17 at 01:29
23

I came across this question looking for a way to open an Explorer window from PowerShell and also select a file. I'm adding this answer in case others come across it for the same reason.

To launch Explorer and select a file, use Invoke-Expression:

Invoke-Expression "explorer '/select,$filePath'"

There are probably other ways to do this, but this worked for me.

Carson
  • 6,105
  • 2
  • 37
  • 45
shovavnik
  • 2,878
  • 3
  • 24
  • 21
  • 1
    +1. Thanks for this. If the path has spaces in this then this will work. `Invoke-Expression "explorer '/select,""$filePath""'` – Ste Nov 07 '21 at 15:06
11
$startinfo = new-object System.Diagnostics.ProcessStartInfo 
$startinfo.FileName = "explorer.exe"
$startinfo.WorkingDirectory = 'D:\foldername'

[System.Diagnostics.Process]::Start($startinfo)

Hope this helps

codeape
  • 97,830
  • 24
  • 159
  • 188
Alex
  • 12,749
  • 3
  • 31
  • 45
  • 1
    I don't know why this is getting voted down -- I can see not voting it up for the lack of elegance, but it's still a good (though wordy) answer :) You get my UP. – slipsec Nov 26 '08 at 16:52
  • 1
    I agree. It's a lot more code, but it allows some flexibility. – Mike Shepard Nov 28 '08 at 06:23
  • When I use this code, it opens Explorer, but not the directory I passed as the WorkingDirectory. It just opens the Libraries folder. The answer shovavnik submitted does it correctly in a single line. – Phoenix14830 Jan 10 '19 at 15:30
6
start explorer.exe 

Simple single line command

Jean-François Fabre
  • 137,073
  • 23
  • 153
  • 219
5

This is the only thing that fit my unique constraints of wanting the folder to open as a Quizo Tab in any existing Explorer window.

$objShell = New-Object -ComObject "Shell.Application"
$objShell.Explore("path")
Beej
  • 794
  • 8
  • 15
  • This really seems to be the best answer. Not only does this ensure that folders open in Directory Opus, Quizo Tab, or whatever custom file explorer you might have, but it's more secure. If you're trying to open a path based on user input, most of these answers allow execution of arbitrary shell commands and executables. As far as I can tell, the method described in this answer can only open a default file explorer window to a desired location. Trying to pass in C:\Windows\System32\calc.exe for instance, results in an error. – Phistrom Aug 04 '20 at 17:54
3

Single line command ,this worked for me

explorer .\

mutong
  • 31
  • 1
2

I wanted to write this as a comment but I do not have 50 reputation.

All of the answers in this thread are essentially to use Invoke-Item or to use explorer.exe directly; however, this isn't completely synonymous with "open containing folder", so in terms of opening an Explorer window as the question states, if we wanted to apply the answer to a particular file the question still hasn't really been answered.

e.g.,

Invoke-Item C:\Users\Foo\bar.txt
explorer.exe C:\Users\Foo\bar.html

^ those two commands would result in Notepad.exe or Firefox.exe being invoked on the two files respectively, not an explorer.exe window on C:\Users\Foo\ (the containing directory).

Whereas if one was issuing this command from powershell, this would be no big deal (less typing anyway), if one is scripting and needs to "open containing folder" on a variable, it becomes a matter of string matching to extract the directory from the full path to the file.

Is there no simple command "Open-Containing-Folder" such that a variable could be substituted?

e.g.,

$foo = "C:\Users\Foo\foo.txt"    
[some code] $fooPath
# opens C:\Users\Foo\ and not the default program for .txt file extension
T Sandwich
  • 53
  • 5
1

for powershell maybe this is an idea for windows 11, i did not figure out how to open all locations/folders in one window with n tabs. $c = @('c:\users', 'c:', 'c:\temp'); Invoke-Item $c

Vsn
  • 21
  • 3
0

If you need certain credential to access to a folder (or a UNC path), explorer $fooPath will prompt you for the credential, but Invoke-Item or Set-Location $fooPath will throw an ItemNotFoundException.