Quick Tip: Open A File In Default Program

When you double click a file in Explorer.exe, it automatically opens in its default program if it has one associated with its type. But did you know you can do the same thing using PowerShell?

Most people are aware of Start-Process, the PowerShell cmdlet for starting processes on the computer, but most people just use it for executing things they’d normally just look to run in cmd.exe like installers. But Start-Process has a -FilePath parameter that you can use to open a file in its default program.

On my computer, this command opens the given CSV in Excel. This is handy in situations where you’re poking around in the console, exporting files, and then perhaps you wish to open that file and rather than clicking around inefficiently through Explorer.exe, you can just launch it from the PowerShell CLI.

3 thoughts on “Quick Tip: Open A File In Default Program

    1. It appears:
      ‘invoke-item’ does nothing more that send the file to the operating system for the default handler to deal with it.
      ‘start-process’ allows you to see the process from within powershell. ie:
      $p = Start-Process ping -ArgumentList “” -wait -NoNewWindow -PassThru
      Notice the -wait so that the next line ($p.HasExited) will not execute until the program finishes. Could eliminate that and generate errors if the run takes too long, etc…

Leave a Reply

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