Project

PSWriteOffice

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

Stars158
Forks14
Open issues0
PowerShell Gallery downloads158661
Releasev3.0.5
Language: C# Updated: 2026-08-20T06:15:04.0000000+00:00

Documentation

Update Existing Word Documents

Replace content and modify targeted Word structures while preserving the rest of an existing DOCX document.

Updating an existing document is different from rebuilding it. Use the smallest command that owns the intended change, preserve the original as input when auditability matters, and reopen the result to verify the change.

Update-OfficeWordText can update visible text and, when explicitly selected, hyperlink text, URI, anchor, and tooltip metadata.

Update-OfficeWordText -Path '.\Input\FY24-Report.docx' `
    -OldValue 'FY24' -NewValue 'FY25' `
    -IncludeHyperlinkText -IncludeHyperlinkUri `
    -IncludeHyperlinkAnchor -IncludeHyperlinkTooltip

Use -WhatIf before a broad replacement. Find-OfficeWord can count the old and new values before and after the operation.

Modify live objects

For structural work, open an editable document and pipe the specific object to commands such as Set-OfficeWordParagraph, Set-OfficeWordText, Set-OfficeWordTableCell, Set-OfficeWordImage, or Set-OfficeWordDocumentProperty. Save or close with -Save only after all changes succeed.

The update-existing recipe demonstrates link-aware replacement. Example-WordModifyExistingObjects.ps1 shows object-level changes.

Preserve intent

A targeted update should not silently restructure unrelated content. For large template changes, create a new version and use Word comparison and review instead of treating a complex rewrite as a text replacement.