PowerShell script to find and replace text in a file

Powershell Script to Find and Replace Text in a File

To find and replace a particular word throughout a file on multiple computers is as laborious as one can imagine. However, with the help of the following PowerShell script, one can easily find a particular word and replace it with a word of choice.
 
To do so, provide the file path, the text to find, and the text to be replaced as parameters and run the script. 

Script

<#
.SYNOPSIS
This script can be used to find a text and replace it with a desired text in a file.
.DESCRIPTION
This script can be used to find a text and replace it with a desired text in a file.
.EXAMPLE
C:\PS> C:\Script\Find_and_Replace.ps1 C:\Script\test.txt powershell windowspowershell
Finds ‘powershell’ in C:\Script\test.txt and replaces it with ‘windows powershell’.
#>

param([String] $file,[String] $source , [String] $replace)
#Get the entire file content.

$content = Get-Content $file
$content
Write-Host
#Replace the source word with the replace word.

$content = $content -creplace $source,$replace
$content
#set the file content.

$content | Set-Content $file