Translate

Monday, October 13, 2014

Powershell replace files

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
}

No comments:

Post a Comment

Comments will appear once they have been approved by the moderator