There are programs allows us to "View File in Explorer" on a file it opened or is listing (e.g. iTunes). Upon selecting that function, the file explorer is opened to the path containing that file and the corresponding file is highlighted. This is the feature I would like to emulate with PowerShell.

It is simple to open to a directory with PowerShell (i.e. explorer $path). However, attempting to include a file just opens that file with the associated program (e.g. doing explorer $path/$file where $file is a .txt file will just open $file in notepad or whatever program is defined to handle .txt files).

Can PowerShell open the File Explorer to a specific path AND highlight a specific file?


It is possible to select a specific file by sending the select command to explorer.exe. This is actually native to cmd. So, the $path is restricted to the traditional DOS format (e.g. using \ only instead of both \ and /).

# Both Works on PowerShell 5
explorer /select,$path
Invoke-Expression "explorer '/select,$path'"

This info is from this answer by Alex (thanks to AEonAX for pointing this out).

  • Also works with double quotes explorer.exe "/select,C:\path\to\file.txt". I've found that the important thing is to wrap the whole /select and file name in quotes. – TechSpud Feb 16 '17 at 7:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.