Project

PSWriteOffice

PowerShell document automation across OfficeIMO's document, spreadsheet, presentation, PDF, Project, Access, EPUB, invoicing, and conversion engines.

Stars 654
Forks 82
Open issues 1
Total downloads 4,320,051
Release OfficeIMO-v3.5.3
Language: C# Updated: 2026-11-03
Cmdlet

Update-OfficeWordTableOfContents

Module
PSWriteOffice
Inputs
OfficeIMO.Word.WordDocument OfficeIMO.Word.WordTableOfContent
Outputs
OfficeIMO.Word.WordTableOfContent

Updates the table of contents in a Word document.

Syntax

Update-OfficeWordTableOfContents
[-Document <WordDocument>]
[-PassThru]
[-Regenerate]
[<CommonParameters>]
#
Parameter set: Document
Update-OfficeWordTableOfContents
[-PassThru]
[-Regenerate]
[-TableOfContents <WordTableOfContent>]
[<CommonParameters>]
#
Parameter set: TableOfContents

Examples

Mark table of contents for refresh on open.

New-OfficeWord -Path .\ExecutiveReport.docx {
    Add-OfficeWordTableOfContents
    Add-OfficeWordParagraph -Text 'Executive summary' -Style Heading1
    Add-OfficeWordParagraph -Text 'Summary text'
    Update-OfficeWordTableOfContents
}

Marks TOC fields as dirty and updates the document settings so Word refreshes the TOC when opened.

Regenerate a TOC in an existing document object.

$doc = Get-OfficeWord -Path .\Report.docx
$doc | Update-OfficeWordTableOfContents -Regenerate
$doc | Save-OfficeWord -Path .\Report-RegeneratedToc.docx

Uses OfficeIMO's regenerate path, then saves the updated document.

Parameters

-Document WordDocument optionalpipeline: True (ByValue)sets: Document
Document to update when provided explicitly.
-PassThru SwitchParameter optional
Emit the updated table of contents.
-Regenerate SwitchParameter optional
Rebuild the table of contents before updating.
-TableOfContents WordTableOfContent optionalpipeline: True (ByValue)sets: TableOfContents
Table of contents to update.

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.