Skip to main content

Search OfficeIMO

Enter a topic, API type, or PowerShell command.

Documentation Search all OfficeIMO/
Cmdlet

New-OfficeWord

Module
PSWriteOffice
Inputs
None
Outputs
OfficeIMO.Word.WordDocument System.IO.FileInfo

Creates a themed Word document, returning a live document or saving a completed content block.

Syntax

New-OfficeWord
[-Force]
[[-Path] <String>]
[-Template <String>]
[-Theme <OfficeThemeInput>]
[<CommonParameters>]
#
Parameter set: Live
New-OfficeWord
[-AllowLoss]
[-Content] <ScriptBlock>
[-Force]
[-PassThru]
[-Password <SecureString>]
[-Path] <String>
[-Show]
[-Template <String>]
[-Theme <OfficeThemeInput>]
[<CommonParameters>]
#
Parameter set: Content

Description

Without a block no file is written, including on disposal. A block saves atomically; an existing destination requires Force. Template copies content, while Theme reads only the source theme.

Examples

Create and save a report.

New-OfficeWord -Path ./Report.docx -Theme Modern -PassThru {
    WordHeading 'Service review'
    WordParagraph 'All services are available.'
}

Create a live document for explicit editing and saving.

$document = New-OfficeWord -Theme Boardroom
$document | Add-OfficeWordParagraph -Text 'Reviewed and approved'
Save-OfficeWord -Document $document -Path ./Review.docx
Close-OfficeWord -Document $document

Parameters

-Force SwitchParameter optional
Allow a completed content block to replace an existing destination.
-Path String required in Contentposition: 0aliases: FilePath
Optional associated destination for a live document; required when a content block saves a file.
-Template String optional
Existing Word package copied as starting content. Its styling is preserved unless Theme is supplied.
-Theme OfficeThemeInput optional
Built-in theme, theme object or a document/template whose visual theme is read.
-AllowLoss SwitchParameter optionalsets: Content
Explicitly accept reductions reported by the content block's native save.
-Content ScriptBlock requiredposition: 1sets: Content
Authoring block to complete before the document is atomically saved and closed.
-PassThru SwitchParameter optionalsets: Content
Return the saved FileInfo after a completed content block.
-Password SecureString optionalsets: Content
Password for a completed content block's saved file; use Save-OfficeWord for a live document.
-Show SwitchParameter optionalsets: Content
Open the saved result in its registered application after the content block succeeds.

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.