Project

PSWriteOffice

PowerShell document automation across OfficeIMO's document, spreadsheet, presentation, PDF, Project, Access, EPUB, invoicing, and conversion engines.

Stars 654
Forks 82
Open issues 1
Total downloads 4,320,051
Release OfficeIMO-v3.5.3
Language: C# Updated: 2026-11-03
Cmdlet

New-OfficeWord

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

Creates a Word document using the DSL.

Syntax

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

Description

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

Examples

Create a document inline.

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.

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.

$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.

Parameters

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

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.