How to open any file with its default application with PowerShell?

PowerShellMicrosoft TechnologiesSoftware & Coding

To open any file using its default application, we can use the Invoke-Expression command. For example, we want to open a file on the C:\temp and the file name is NewUsers.CSV then you can run the below command.

Invoke-Expression C:\Temp\NewUsers.csv

The above command will open the file from that location. If the default application is not set then Windows will ask for the default application to select.

If you know any application name and which can be opened with the shortcut then you can directly type the name of the application. For example, Notepad.exe, Calc.exe

Generally, they can be opened directly but this command also helps to open the application as shown below.

PS C:\> Invoke-Expression notepad.exe
PS C:\> Invoke-Expression calc.exe
raja
Published on 20-Nov-2020 08:51:32
Advertisements