The powershell script below replaces all occurrences of the file Hello.txt in the path C:\Users\menonv\Desktop with that from C:\test\Hello.txt
Clear-Host
$searchPath= "C:\Users\menonv\Desktop"
$fileToBeReplaced="Hello.txt"
$replacementFile="C:\test\Hello.txt"
set-location $searchPath
$ReplaceTheseFiles=get-childitem $fileToBeReplaced -rec
foreach ($file in $ReplaceTheseFiles)
{
Write-Host "Replacing File" $file with $replacementFile
Copy-Item $replacementFile $file
}
Clear-Host
$searchPath= "C:\Users\menonv\Desktop"
$fileToBeReplaced="Hello.txt"
$replacementFile="C:\test\Hello.txt"
set-location $searchPath
$ReplaceTheseFiles=get-childitem $fileToBeReplaced -rec
foreach ($file in $ReplaceTheseFiles)
{
Write-Host "Replacing File" $file with $replacementFile
Copy-Item $replacementFile $file
}