# Update-OfficeWordText

Replaces text in a Word document. Review available syntax, parameters, pipeline guidance, and reference details in PSWriteOffice Cmdlet Reference.

Cmdlet 

**Module**

`PSWriteOffice`

**Inputs**

`OfficeIMO.Word.WordDocument` `System.String[]`

**Outputs**

`System.Int32`

**Source**

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

Replaces text in a Word document.

## Syntax

```
Update-OfficeWordText
[-CaseSensitive]
[-IncludeHyperlinkAnchor]
[-IncludeHyperlinkText]
[-IncludeHyperlinkTooltip]
[-IncludeHyperlinkUri]
-NewValue <String>
-OldValue <String>
[-PassThru]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
```

[#](#method-update-officewordtext-switchparameter-switchparameter-switchparameter-switchparameter-switchparameter-string-string-switchparameter-switchparameter-switchparameter)

Parameter set: `Context`

```
Update-OfficeWordText
[-CaseSensitive]
-Document <WordDocument>
[-IncludeHyperlinkAnchor]
[-IncludeHyperlinkText]
[-IncludeHyperlinkTooltip]
[-IncludeHyperlinkUri]
-NewValue <String>
-OldValue <String>
[-PassThru]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
```

[#](#method-update-officewordtext-switchparameter-worddocument-switchparameter-switchparameter-switchparameter-switchparameter-string-string-switchparameter-switchparameter-switchparameter)

Parameter set: `Document`

```
Update-OfficeWordText
[-CaseSensitive]
[-IncludeHyperlinkAnchor]
[-IncludeHyperlinkText]
[-IncludeHyperlinkTooltip]
[-IncludeHyperlinkUri]
-NewValue <String>
-OldValue <String>
[-PassThru]
[-Path] <String[]>
[-Show]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
```

[#](#method-update-officewordtext-switchparameter-switchparameter-switchparameter-switchparameter-switchparameter-string-string-switchparameter-string-switchparameter-switchparameter-switchparameter)

Parameter set: `Path`

```
Update-OfficeWordText
[-CaseSensitive]
[-IncludeHyperlinkAnchor]
[-IncludeHyperlinkText]
[-IncludeHyperlinkTooltip]
[-IncludeHyperlinkUri]
-LiteralPath <String[]>
-NewValue <String>
-OldValue <String>
[-PassThru]
[-Show]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
```

[#](#method-update-officewordtext-switchparameter-switchparameter-switchparameter-switchparameter-switchparameter-string-string-string-switchparameter-switchparameter-switchparameter-switchparameter)

Parameter set: `LiteralPath`

## Description

Supports direct document objects, file paths, and the active DSL document. Hyperlink labels and metadata can be updated when requested.

## Guides & Samples

Authored walkthroughs and practical samples linked to this command.

- [Update Existing Word Documents](/docs/pswriteoffice/word-update-existing/) Guide
  
  Replace content and modify targeted Word structures while preserving the rest of an existing DOCX document.
- [Generate Word Documents from DOCX Templates](/docs/word/templates/) Guide
  
  Fill DOCX templates from C# data with placeholders, repeated and conditional blocks and images, run MERGEFIELD mail merge, and fill content controls.

## Examples

### Replace text in an open document.

```powershell
$count = $doc | Update-OfficeWordText -OldValue 'FY24' -NewValue 'FY25' -PassThru
```

Updates matching text in the loaded document and returns the number of replacements.

### Replace hyperlink targets in a file.

```powershell
Update-OfficeWordText -Path .\Report.docx -OldValue 'old.example.com' -NewValue 'new.example.com' -IncludeHyperlinkUri
```

Loads the document, updates matching hyperlink URLs, saves the file, and closes it.

## Parameters

**-CaseSensitive SwitchParameter optional**

Use case-sensitive matching.

**-IncludeHyperlinkAnchor SwitchParameter optional**

Also replace hyperlink anchors.

**-IncludeHyperlinkText SwitchParameter optional**

Also replace hyperlink display text.

**-IncludeHyperlinkTooltip SwitchParameter optional**

Also replace hyperlink tooltips.

**-IncludeHyperlinkUri SwitchParameter optional**

Also replace hyperlink URIs.

**-NewValue String required**

Replacement text.

**-OldValue String required**

Text to find.

**-PassThru SwitchParameter optional**

Emit the object created or changed by the command.

**-WhatIf SwitchParameter optional**

Shows what would happen if the command runs.

**-Confirm SwitchParameter optional**

Prompts for confirmation before running the command.

**-Document WordDocument requiredpipeline: True (ByValue)sets: Document**

Document to update.

**-Path String[] requiredposition: 0pipeline: True (ByValue)aliases: FilePath, InputPathsets: Path**

Path to the .docx file to update in place.

**-Show SwitchParameter optionalsets: Path, LiteralPath**

Open the file after saving when using -Path.

**-LiteralPath String[] requiredpipeline: True (ByPropertyName)aliases: FullName, PSPathsets: LiteralPath**

Literal input files, including FileInfo.FullName.

## 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:015644CFEB4435D6B2157E205AA11DFCEBB74721CB1BD78C6F8B11FA6FDE5ACE -->
