# Add-OfficeWordTableOfContents

Adds a table of contents to a Word document. Review available syntax, parameters, pipeline guidance, and reference details in PSWriteOffice Cmdlet Reference.

Cmdlet 

Aliases: WordTableOfContents

**Module**

`PSWriteOffice`

**Aliases**

`WordTableOfContents`

**Inputs**

`OfficeIMO.Word.WordDocument`

**Outputs**

`OfficeIMO.Word.WordTableOfContent`

**Source**

[AddOfficeWordTableOfContentsCommand.cs:24](https://github.com/EvotecIT/OfficeIMO/blob/be6c300e4ab1859837b961c64fbfb2b2a1886cd0/PowerShell/PSWriteOffice/Sources/PSWriteOffice/Cmdlets/Word/AddOfficeWordTableOfContentsCommand.cs#L24) 

Adds a table of contents to a Word document.

## Syntax

```
Add-OfficeWordTableOfContents
[-Document <WordDocument>]
[-PassThru]
[-Style <Template1|Template2>]
[<CommonParameters>]
```

[#](#method-add-officewordtableofcontents-worddocument-switchparameter-wordtableofcontentsstyle)

Parameter set: `Default`

## Guides & Samples

Authored walkthroughs and practical samples linked to this command.

- [Migrate from PSWriteWord to PSWriteOffice](/docs/pswriteoffice/migrate-from-pswriteword/) Guide
  
  Replace archived PSWriteWord scripts with maintained PSWriteOffice Word commands for DOCX creation, editing, review, merge, and conversion.
- [Add a Table of Contents and Fields in Word](/docs/word/fields-toc/) Guide
  
  Insert a table of contents, page, date and property fields into DOCX files, refresh them on open or in code, and read fields with OfficeIMO.Word.

## Examples

### Add a table of contents before report sections.

```powershell
New-OfficeWord -Path .\ExecutiveReport.docx {
    Add-OfficeWordTableOfContents -Style Template1
    Add-OfficeWordParagraph -Text 'Executive summary' -Style Heading1
    Add-OfficeWordParagraph -Text 'Summary text'
    Add-OfficeWordParagraph -Text 'Appendix' -Style Heading1
    Add-OfficeWordParagraph -Text 'Supporting details'
    Update-OfficeWordTableOfContents
}
```

Creates a navigable report outline and marks the TOC for refresh when the document opens.

## Parameters

**-Document WordDocument optionalpipeline: True (ByValue)**

Document to modify when provided explicitly.

**-PassThru SwitchParameter optional**

Emit the created table of contents.

**-Style WordTableOfContentsStyle optional**

Table of contents template style.

Possible values: `Template1`, `Template2`

## 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](https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_commonparameters).

<!-- PowerForge markdown artifact sha256:50777C90BCF053D640B37BDCE80D5E147C2375BD81D519CE5167EAD3900120C6 -->
