Cmdlet
Update-OfficeWordText
Replaces text in a Word document.
Syntax
Update-OfficeWordText
[-CaseSensitive]
[-IncludeHyperlinkAnchor]
[-IncludeHyperlinkText]
[-IncludeHyperlinkTooltip]
[-IncludeHyperlinkUri]
-NewValue <String>
-OldValue <String>
[-PassThru]
[-WhatIf]
[-Confirm]
[<CommonParameters>]#Parameter set:
ContextUpdate-OfficeWordText
[-CaseSensitive]
-Document <WordDocument>
[-IncludeHyperlinkAnchor]
[-IncludeHyperlinkText]
[-IncludeHyperlinkTooltip]
[-IncludeHyperlinkUri]
-NewValue <String>
-OldValue <String>
[-PassThru]
[-WhatIf]
[-Confirm]
[<CommonParameters>]#Parameter set:
DocumentUpdate-OfficeWordText
[-CaseSensitive]
[-IncludeHyperlinkAnchor]
[-IncludeHyperlinkText]
[-IncludeHyperlinkTooltip]
[-IncludeHyperlinkUri]
-NewValue <String>
-OldValue <String>
[-PassThru]
[-Path] <String[]>
[-Show]
[-WhatIf]
[-Confirm]
[<CommonParameters>]#Parameter set:
PathUpdate-OfficeWordText
[-CaseSensitive]
[-IncludeHyperlinkAnchor]
[-IncludeHyperlinkText]
[-IncludeHyperlinkTooltip]
[-IncludeHyperlinkUri]
-LiteralPath <String[]>
-NewValue <String>
-OldValue <String>
[-PassThru]
[-Show]
[-WhatIf]
[-Confirm]
[<CommonParameters>]#Parameter set:
LiteralPathDescription
Supports direct document objects, file paths, and the active DSL document. Hyperlink labels and metadata can be updated when requested.
Examples
Replace text in an open document.
$count = $doc | Update-OfficeWordText -OldValue 'FY24' -NewValue 'FY25' -PassThruUpdates matching text in the loaded document and returns the number of replacements.
Replace hyperlink targets in a file.
Update-OfficeWordText -Path .\Report.docx -OldValue 'old.example.com' -NewValue 'new.example.com' -IncludeHyperlinkUriLoads the document, updates matching hyperlink URLs, saves the file, and closes it.
Parameters
- -CaseSensitive SwitchParameter
- Use case-sensitive matching.
- -IncludeHyperlinkAnchor SwitchParameter
- Also replace hyperlink anchors.
- -IncludeHyperlinkText SwitchParameter
- Also replace hyperlink display text.
- -IncludeHyperlinkTooltip SwitchParameter
- Also replace hyperlink tooltips.
- -IncludeHyperlinkUri SwitchParameter
- Also replace hyperlink URIs.
- -NewValue String
- Replacement text.
- -OldValue String
- Text to find.
- -PassThru SwitchParameter
- Emit the object created or changed by the command.
- -WhatIf SwitchParameter
- Shows what would happen if the command runs.
- -Confirm SwitchParameter
- Prompts for confirmation before running the command.
- -Document WordDocument
- Document to update.
- -Path String[]
- Path to the .docx file to update in place.
- -Show SwitchParameter
- Open the file after saving when using -Path.
- -LiteralPath String[]
- 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.