API Reference
New-OfficeWord
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
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>]#All Parameter SetsParameters
- Content ScriptBlock
- DSL scriptblock describing document content.
- NoSave SwitchParameter
- Skip saving after executing the DSL.
- Open SwitchParameter
- Open the document after saving.
- PassThru SwitchParameter
- Emit a FileInfo for chaining.
- Password String
- Password used to save the document as an encrypted package.
- Path String
- Destination path for the document.
- TemplatePath String
- Existing .docx file to clone before running the DSL.