Would you like to learn how to replace words in a text file using Powershell? In this tutorial, we are going to show you how to use Powershell to replace a string from a text file on a computer running Windows.

• Windows 2012 R2
• Windows 2016
• Windows 2019
• Windows 10
• Windows 7

Equipment list

The following section presents the list of equipment used to create this tutorial.

As an Amazon Associate, I earn from qualifying purchases.

Related tutorial - PowerShell

On this page, we offer quick access to a list of tutorials related to PowerShell.

Tutorial Powershell - Replace text in a File

Start a Powershell command-line.

Start Powershell

Create a text file.

Copy to Clipboard

In our example, we create a text file named MYFILE in the root of drive C.

Get the content of a file and replace a specific word.

Copy to Clipboard

Here is the command output.

Copy to Clipboard

In our example, we replaced the string GOKU with the word GOTEN.

This will only display the result on the screen.

Replace a word in the text file.

Copy to Clipboard

There are multiple ways to replace a string in a file.

Copy to Clipboard

Congratulations! You are able to replace words in a text file using Powershell.