How to Open Microsoft Word Document Using PowerShell
Introduction
Having the ability to open Ms Word document from PowerShell is extremely useful. It can save you time and energy by allowing you to quickly edit the document without having to open Microsoft Word program manually.
In this article, we will walk you through how to open Ms Word document using PowerShell.
Solution
In general, solution to this problem consists of three parts:
- Using cmdlet or operator to open the document
- Specifying the executable file of Ms Word
- Specifying the path of the document
Using Start Winword command
Among many solutions, this one is pretty different that it doesn’t need to specify Ms Word executable file similar to solution using Invoke-Item. Winword
is recognized as Microsoft Word process while Start
is the alias of Start-Process
cmdlet in Windows environment.
start winword 'C:\Scripts\documentation.docx'
Using Start-Process
Once you are in PowerShell environment, you can type in Start-Process
followed by the path of your Ms Word executable file and the document.
In this case, we are going to open Ms Word where the executable file is physically located at C:\Program Files\Microsoft Office\root\Office16\WINWORD.EXE
and the document path is C:\Scripts\documentation.docx
, you would type following script into PowerShell.
Start-Process 'C:\Program Files\Microsoft Office\root\Office16\WINWORD.EXE' 'C:\Scripts\documentation.docx'
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:\Program Files\Microsoft Office\root\Office16\WINWORD.EXE' 'C:\Scripts\documentation.docx'
Using Invoke-Item
Invoke-Item
cmdlet can also be used to invoke any item such as Word document. However, we cannot specify Ms Word executable file.
Assuming .docx
is recognized as Word document and Ms Word is already installed, we can just directly open the document.
Invoke-Item 'C:\Scripts\documentation.docx'
Using Call Operator (&)
Call Operator &
can also be used to open Word document. 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:\Program Files\Microsoft Office\root\Office16\WINWORD.EXE' 'C:\Scripts\documentation.docx'
Using Dot (.) Operator
Likewise, Dot .
Operator can also be used to open Word document. 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:\Program Files\Microsoft Office\root\Office16\WINWORD.EXE' 'C:\Scripts\documentation.docx'
Conclusion
We can open Ms Word document using PowerShell. We just need to use correct cmdlet or operator, then followed by the path of Ms Word executable file and the document we want to open.