Even if you prefer working at a command prompt, in some cases you might want to switch to the GUI. For example, File Explorer might be more efficient if you have to work with a large number of files that you can’t simply select with a pattern such as *.txt. In such a scenario you probably want to open File Explorer from PowerShell at a specific destination folder.

Start-Process for directories ^

If you want to open File Explorer from your current location on the command line, you could do this with the following command:

explorer .

cmd.exe knows the start command, which offers a variety of additional optional commands for the execution of a program. The next simple command also opens Explorer in the current folder:

Start .

In PowerShell, the start command exists as an alias of the Start-Process cmdlet. If you pass the name of a directory as an argument, it will open Explorer at this location. In the above case, this would be “.\”; however, you can use any other path.

Starting File Explorer in the current folder

Starting File Explorer in the current folder

Of course, in addition to explicitly passing a directory, you can also work with variables here. For instance, the following command displays the home directory of the currently logged-on user in File Explorer:

Start $env:USERPROFILE

Other useful environment variables are SystemRoot and TEMP.

Executing with administrative rights ^

You can also execute a new process with administrative rights by passing the parameter runas:

Start explorer.exe $pwd -verb runas

In most cases, you don’t need this feature when starting Explorer. It would be more interesting for a new command line with administrative rights. This works, but cmd.exe and PowerShell ignore the working directory if you pass it as a variable with the above pattern.

Full screen or normal window ^

If you want, you can also determine if the corresponding program will start in a normal window, minimized, or in full screen mode:

Start . -WindowStyle Maximized

The alternatives to Maximized are Minimized, Normal, and Hidden, although the latter is rarely useful in practice.

Opening multiple directories simultaneously ^

A restriction of Start-Process is that it can only start one process per call. For example, if you want to open two folders in Explorer in order to copy files between them, Invoke-Item is the better option:

Invoke-Item .\Documents, .\Downloads

This call would display the current folder's subdirectories Documents and Downloads in Explorer. In this case, you can’t use the WindowStyle parameter.

1 Comment
  1. hr 6 months ago

    Is it possible to use powershell to open File Explorer with a subset of wildcard matched files?

    For instance, when I start power shell it starts me in my c:\ users folder. I have a folder located at D:\test\This\Out. I contains *.txt, *.jpg, and *.docx files. I would like to open Windows Explorer with only the following files displayed within the explorer: *.jpg. There are hundreds of files in the folder. I specifically want display just the files matching this wildcard “d:\test\this\out\h100*.jpg” which should result in displaying a fully functional file explorer with only the files matching that string I just mentioned. Currently, about 164 files should be present in the view.

    I have tried all sorts of ways to invoke explorer, start explorer, using invoke-item, invoice-expression, use the file system object and setting a workingdirectory which doesn’t work at all. I’ve tried setting the path as the second parameter. Again, nothing happens.

    Any suggestions on how to make this work?

Leave a reply to hr Click here to cancel the reply

Please enclose code in pre tags

Your email address will not be published.

*

© 4sysops 2006 - 2022

CONTACT US

Please ask IT administration questions in the forums. Any other messages are welcome.

Sending

Log in with your credentials

or    

Forgot your details?

Create Account