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

Close-OfficeWord

Namespace PSWriteOffice
Inputs
OfficeIMO.Word.WordDocument

Closes one or more tracked Word documents, optionally saving them.

Remarks

Provides a cmdlet wrapper for WordDocument.Dispose/Save so scripts need not call .NET methods directly.

Examples

Authored help example

Close without saving.

PS>


$doc = Get-OfficeWord -Path .\Report.docx; Close-OfficeWord -Document $doc
        

Disposes the loaded document instance without saving changes.

Close the most recently tracked document.

PS>


Close-OfficeWord
        

Closes the current tracked document when a document handle is not passed explicitly.

Save to a new path and open the file.

PS>


Close-OfficeWord -Document $doc -Save -Path .\Report-final.docx -Open
        

Saves updates to Report-final.docx, opens it, and disposes the document.

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

Close-OfficeWord [-Current] [-Open] [-Password <String>] [-Path <String>] [-Save] [<CommonParameters>]
#
Parameter set: Current

Parameters

Current SwitchParameter optionalposition: namedpipeline: False
Close the most recently tracked document.
Open SwitchParameter optionalposition: namedpipeline: Falsealiases: Show
Open the file after saving. Requires -Save or -Path.
Password String optionalposition: namedpipeline: False
Password used to save the document as an encrypted package.
Path String optionalposition: namedpipeline: False
Optional target path when saving.
Save SwitchParameter optionalposition: namedpipeline: False
Persist changes before closing.
Close-OfficeWord -Document <WordDocument> [-Open] [-Password <String>] [-Path <String>] [-Save] [<CommonParameters>]
#
Parameter set: Document

Parameters

Document WordDocument requiredposition: 0pipeline: True (ByValue)
Word document to close.
Open SwitchParameter optionalposition: namedpipeline: Falsealiases: Show
Open the file after saving. Requires -Save or -Path.
Password String optionalposition: namedpipeline: False
Password used to save the document as an encrypted package.
Path String optionalposition: namedpipeline: False
Optional target path when saving.
Save SwitchParameter optionalposition: namedpipeline: False
Persist changes before closing.
Close-OfficeWord -All [-Open] [-Password <String>] [-Save] [<CommonParameters>]
#
Parameter set: All

Parameters

All SwitchParameter requiredposition: namedpipeline: False
Close all tracked documents for the current runspace.
Open SwitchParameter optionalposition: namedpipeline: Falsealiases: Show
Open the file after saving. Requires -Save or -Path.
Password String optionalposition: namedpipeline: False
Password used to save the document as an encrypted package.
Save SwitchParameter optionalposition: namedpipeline: False
Persist changes before closing.