Find and Replace parts of a File Name
The following script will find and replace part of a file name with another string.
# Define the path to the folder containing the files
$folderPath = "C:\path\to\your\folder"
# Get all the files in the folder
$files = Get-ChildItem -Path $folderPath -File
# Loop through each file and rename if necessary
foreach ($file in $files) {
$newFileName = $file.Name.Replace("Server2", "Server3")
if ($newFileName -ne $file.Name) {
Rename-Item -Path $file.FullName -NewName $newFileName
Write-Host "Renamed $($file.Name) to $newFileName"
}
}