PowerTip: Use Windows PowerShell to Open Word Document


Summary: Learn how to use Windows PowerShell to open a Microsoft Word document.

Hey, Scripting Guy! Question How can I open a Word document with Windows PowerShell?

Hey, Scripting Guy! Answer Use the New-Object cmdlet:

$Filename='C:\HappyBirthdayEd.docx'

$Word=NEW-Object –comobject Word.Application

$Document=$Word.documents.open($Filename)

You can now programmatically access methods and properties to edit the Word document.

Comments (6)

  1. New-object performs loads of tasks! Thanks for sharing.

  2. @cb

    Correct Word must be installed and the other part is to make sure you didn’t get a typo in the filename location. I’ve got it running on Windows 8.1 as well 🙂

    Sean

  3. Sam Boutros says:

    @ CB:
    I believe you have to have Word installed.
    When I run $Document | Get-Member, I can see hundreds of properties and methods..

  4. CB says:

    PowerShell 3.0
    $Word.Documents -eq $null is true….
    What am I missing?

  5. tellmeonce says:

    is there a way to open any type a document with the appropriate applications using powershell? I have the code to open a form that displays the users home directory and i want them to be able to double click a word, excel, pdf, etc and it open with the
    associated application.

  6. Andrew says:

    how can I add a property "Open ready only"? I get a prompt "File in use"

Skip to main content