How to Open Text File in Notepad Using PowerShell
Introduction
Having the ability to open text file to Notepad from PowerShell is extremely useful. It can save you time and energy by allowing you to quickly edit text files without opening the program manually.
In this article, we’ll walk through how to open text file in notepad using PowerShell.
Solution
This problem consists of two parts:
- Using cmdlet or operator to open either
Notepad
orNotepad++
- Specifying the executable file of either
Notepad
orNotepad++
- Specifying the path of text file
The second step is important because if we install both Notepad
and Notepad++
, typically the text file will be opened in either of those application.
Using Start-Process
Once you are in PowerShell environment, you can type in Start-Process
followed by the path of your Notepad executable file and text file.
In this case, we are going to open Notepad where the executable file is physically located at C:\WINDOWS\system32\notepad.exe
and text file path is C:\Scripts\test.txt
, you would type following script into PowerShell.
Start-Process 'C:\WINDOWS\system32\notepad.exe' 'C:\Scripts\test.txt'
If you want to use Notepad++
instead of Notepad
, you can replace the path of Notepad executable file as follows:
Start-Process 'C:\Program Files\Notepad++\notepad++.exe' 'C:\Scripts\test.txt'
Using Command Prompt Start Command
Another useful command is Command Prompt start
Command which can also be used in PowerShell. To use this command, simply enter the command followed by the path of executable file and the text file.
start 'C:\WINDOWS\system32\notepad.exe' 'C:\Scripts\test.txt'
If you want to use Notepad++
instead of Notepad
, you can replace Notepad executable file with the one from Notepad++ as follows:
start 'C:\Program Files\Notepad++\notepad++.exe' 'C:\Scripts\test.txt'
Using Call Operator (&)
Call Operator &
can also be used to open Notepad. The pattern is the same with previous example where the operator must be followed by the path to the executable file and text file.
& 'C:\WINDOWS\system32\notepad.exe' 'C:\Scripts\test.txt'
If you want to use Notepad++
instead of Notepad
, you can replace Notepad executable file with the one from Notepad++ as follows:
& 'C:\Program Files\Notepad++\notepad++.exe' 'C:\Scripts\test.txt'
Using Dot (.) Operator
Dot .
Operator can also be used to open Notepad. The pattern is the same with previous example where the operator must be followed by the path to the executable file and text file.
. 'C:\WINDOWS\system32\notepad.exe' 'C:\Scripts\test.txt'
Or
. 'C:\Program Files\Notepad++\notepad++.exe' 'C:\Scripts\test.txt'
Conclusion
We can open text file in Notepad
or Notepad++
using PowerShell. We just need to use correct cmdlet or operator, then followed by the path of executable file and text file.