Home » Computers » PowerShell batch rename files

PowerShell batch rename files

Append “_v2” to the filename in current and recurse folders:

dir -Recurse *.xlsx | Rename-Item -NewName { “$($_.BaseName)_v2$($_.Extension)” }

Remove all “_v2” characters from the filename in current and recurse folders:

dir -Recurse *.xlsx | Rename-Item -NewName { $_.Name -replace “_v2″,”” }

Reduce count of consecutive “_v2” characters from the filename in current and recurse folders:

dir -Recurse *.xlsx | Rename-Item -NewName { $_.Name -replace “_v2_v2″,”_v2” }