Renaming Files

The Rename-Item cmdlet enables you to change the name of an object while leaving its content intact. It’s not possible to move items with the Rename-Item command; for that functionality, you should use the Move-Item cmdlet as described above.

The following command renames a file:

Rename-Item -Path "\\fs\Shared\temp.txt" -NewName "new_temp.txt"

Renaming Multiple Files

To rename multiple files at once, use a script like this:

$files = Get-ChildItem -Path C:\Temp # Create list of files

foreach ($file in $files) {
  $newFileName = $file.Name.Replace("A","B")  # Replace "A" with "B"
  Rename-Item $file $newFileName
}