Evotec

Project

PSWriteOffice

PSWriteOffice is an open-source PowerShell and .NET project with packages, release history, and technical documentation.

Stars 144
Forks 12
Open issues 16
PowerShell Gallery downloads 150,904
Release v0.2.0
Language: C# Updated: 2026-04-06

API Reference

Cmdlet

Close-OfficeWord

Namespace PSWriteOffice
Inputs
OfficeIMO.Word.WordDocument
Outputs
System.Object

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 -Show
        

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] [-Path <String>] [-Save] [-Show] [<CommonParameters>]
#
Parameter set: Current

Parameters

Current SwitchParameter optionalposition: namedpipeline: False
Close the most recently tracked document.
Path String optionalposition: namedpipeline: False
Optional target path when saving.
Save SwitchParameter optionalposition: namedpipeline: False
Persist changes before closing.
Show SwitchParameter optionalposition: namedpipeline: False
Open the file after saving.

Outputs

System.Object

Close-OfficeWord -Document <WordDocument> [-Path <String>] [-Save] [-Show] [<CommonParameters>]
#
Parameter set: Document

Parameters

Document WordDocument requiredposition: 0pipeline: True (ByValue)
Word document to close.
Path String optionalposition: namedpipeline: False
Optional target path when saving.
Save SwitchParameter optionalposition: namedpipeline: False
Persist changes before closing.
Show SwitchParameter optionalposition: namedpipeline: False
Open the file after saving.

Outputs

System.Object

Close-OfficeWord -All [-Save] [-Show] [<CommonParameters>]
#
Parameter set: All

Parameters

All SwitchParameter requiredposition: namedpipeline: False
Close all tracked documents for the current runspace.
Save SwitchParameter optionalposition: namedpipeline: False
Persist changes before closing.
Show SwitchParameter optionalposition: namedpipeline: False
Open the file after saving.

Outputs

System.Object