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.

0 Comments

Leave a reply

Please enclose code in pre tags

Your email address will not be published. Required fields are marked *

*

© 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