New-OfficeWord
Creates a Word document using the DSL.
Syntax
New-OfficeWord
[[-Content] <ScriptBlock>]
[-NoSave]
[-Open]
[-PassThru]
[-Password <String>]
[-Path] <String>
[-TemplatePath <String>]
[<CommonParameters>]#All Parameter SetsDescription
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' } } -OpenBuilds 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-OfficeWordAssociates the output path with a live document, adds content through the pipeline, then saves and closes it once.
Parameters
- -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.
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.