Project

PSWriteOffice

PowerShell document automation across Word, Excel, PowerPoint, PDF, Reader, Confluence, Visio, and open text formats.

Stars 159
Forks 14
PowerShell Gallery downloads 158,661
Release v3.0.5
Language: C# Updated: 2026-09-03

API Reference

Cmdlet

New-OfficeWord

Aliases: OfficeWord, WordNew
Namespace PSWriteOffice
Aliases
OfficeWord WordNew
Inputs
None

Creates a Word document using the DSL.

Remarks

Handles file creation or template cloning, scriptblock execution, explicit save or live-document composition, and emits the document path when -PassThru is used.

Examples

Authored help example

Create a document inline.

PS>


New-OfficeWord -Path .\Report.docx { WordSection { WordParagraph 'Hello DSL' } } -Open
        

Builds a document, adds one paragraph, saves it to disk, and opens it.

Create a document from a template.

PS>


New-OfficeWord -TemplatePath .\Template.docx -Path .\Report.docx { WordParagraph -Text 'Generated content' -StyleId 'ReportBody' }
        

Copies the template to the output path, runs the DSL against the copied document, and saves it.

Keep a document for incremental composition.

PS>


$document = New-OfficeWord -Path .\Report.docx -NoSave
            $document | Add-OfficeWordParagraph -Text 'Status report' -Style Heading1
            $document | Save-OfficeWord
            $document | Close-OfficeWord
        

Associates the output path with a live document, adds content through the pipeline, then saves and closes it once.

Common Parameters

This command supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable.

For more information, see about_CommonParameters.

Syntax

New-OfficeWord [-Content <ScriptBlock>] [-NoSave] [-Open] [-PassThru] [-Password <String>] -Path <String> [-TemplatePath <String>] [<CommonParameters>]
#
Parameter set: All Parameter Sets

Parameters

Content ScriptBlock optionalposition: 1pipeline: False
DSL scriptblock describing document content.
NoSave SwitchParameter optionalposition: namedpipeline: False
Skip saving after executing the DSL.
Open SwitchParameter optionalposition: namedpipeline: False
Open the document after saving.
PassThru SwitchParameter optionalposition: namedpipeline: False
Emit a FileInfo for chaining.
Password String optionalposition: namedpipeline: False
Password used to save the document as an encrypted package.
Path String requiredposition: 0pipeline: Falsealiases: FilePath, OutputPath
Destination path for the document.
TemplatePath String optionalposition: namedpipeline: False
Existing .docx file to clone before running the DSL.