[powershell] Is it possible to open a Windows Explorer window from PowerShell?

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

Any clues?

This question is related to powershell

The answer is


start explorer.exe 

Simple single line command


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 .

$startinfo = new-object System.Diagnostics.ProcessStartInfo 
$startinfo.FileName = "explorer.exe"
$startinfo.WorkingDirectory = 'D:\foldername'

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

Hope this helps


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 .

Single line command ,this worked for me

explorer .\


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")

$startinfo = new-object System.Diagnostics.ProcessStartInfo 
$startinfo.FileName = "explorer.exe"
$startinfo.WorkingDirectory = 'D:\foldername'

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

Hope this helps


explorer .

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.


explorer .

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 .

$startinfo = new-object System.Diagnostics.ProcessStartInfo 
$startinfo.FileName = "explorer.exe"
$startinfo.WorkingDirectory = 'D:\foldername'

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

Hope this helps


explorer .

$startinfo = new-object System.Diagnostics.ProcessStartInfo 
$startinfo.FileName = "explorer.exe"
$startinfo.WorkingDirectory = 'D:\foldername'

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

Hope this helps


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

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.


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")

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.


Single line command ,this worked for me

explorer .\


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")

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 .

start explorer.exe 

Simple single line command


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

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.


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")

explorer .

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")