Is it possible to open a Windows Explorer window from PowerShell?
Asked Answered
R

13

426

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

Any clues?

Retard answered 26/11, 2008 at 12:19 Comment(0)
B
882

Use:

ii .

which is short for

Invoke-Item .

The dot can be substituted with any path.

Beatitude answered 26/11, 2008 at 15:25 Comment(2)
So default first parameter of ii is explorer, second param is path.Circuit
the PowerShell equivalent of start .Valenti
Y
184

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")
Ytterbia answered 26/11, 2008 at 12:55 Comment(3)
You can also do: invoke-item c:\path\Iberian
This is the best worded and most informative answer here, and should also include the other upvoted answers here, especially "ii ."Mastiff
ii is an alias of Invoke-ItemEastwood
R
65

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.

Recognizance answered 7/4, 2017 at 2:40 Comment(0)
G
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 .
Galvin answered 26/11, 2008 at 12:41 Comment(1)
An alias for that is ii .Cotten
L
31
explorer .
Lamas answered 26/11, 2008 at 12:45 Comment(1)
This is what I've been using for years, but recently explorer seems to be out my pathMastiff
D
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.

Damascus answered 28/8, 2012 at 15:43 Comment(2)
+1. Thanks for this. If the path has spaces in this then this will work. Invoke-Expression "explorer '/select,""$filePath""'Haematozoon
@Haematozoon You made a typo, it's: Invoke-Expression "explorer '/select,""$filePath""'"Hassiehassin
A
11
$startinfo = new-object System.Diagnostics.ProcessStartInfo 
$startinfo.FileName = "explorer.exe"
$startinfo.WorkingDirectory = 'D:\foldername'

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

Hope this helps

Alexis answered 26/11, 2008 at 12:29 Comment(3)
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.Otiliaotina
I agree. It's a lot more code, but it allows some flexibility.Chinchin
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.Smoothtongued
F
6
start explorer.exe 

Simple single line command

Felon answered 23/4, 2010 at 12:47 Comment(1)
This works in both Powershell and CMD.Vuong
A
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")
Ammonal answered 11/6, 2017 at 0:47 Comment(1)
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.Shifra
O
4

Single line command ,this worked for me

explorer .\

Orren answered 3/2, 2021 at 9:1 Comment(0)
H
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
Hobo answered 26/8, 2016 at 2:53 Comment(2)
Invoke-Item ([io.fileinfo]"C:\temp\file.txt").DirectoryBrunella
An alternative that is essentially the same but keeps it all in Powershell cmdlets: ii (Split-Path "C:\temp\file.txt")Beatitude
F
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

Filomenafiloplume answered 28/2, 2023 at 16:1 Comment(0)
H
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.

Heimlich answered 7/5, 2023 at 15:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.