Matt W
Matt W

Reputation: 12423

Open file in chosen application in PowerShell

I would like to open a file using the cmdln in PowerShell with a particular application.

In my case, I have a file scripts.js which I'd like to open in Notepad++ but which would normally open in regular notepad.exe if I did this: Invoke-Item .\scripts.js

What should I do to open that file in Notepad++?

Upvotes: 12

Views: 45433

Answers (2)

Will Webb
Will Webb

Reputation: 805

By using Start-Process you can do:

$FileLocation = 'C:\temp\test\scripts.js'
Start-Process notepad++ $FileLocation

Upvotes: 25

Ansgar Wiechers
Ansgar Wiechers

Reputation: 200293

Use the call operator and pass the file as an argument to the program you want to open it with:

& 'C:\path\to\notepad++.exe' '.\script.js'

Upvotes: 8

Related Questions