Bulk rename files in PowerShell with Rename-Item
One pipeline that renames every matching file in a folder using regular expressions — safer and far more flexible than third-party renamers.
01Command
$ Get-ChildItem *.txt | Rename-Item -NewName { $_.Name -replace 'IMG_','Vacation_' }02What it does
Rename-Item renames in place and cannot move files, and the -NewName script block runs once per pipeline object, so `$_` is each file's FileInfo. -replace uses .NET regex: swap in `'^IMG_(\d+)\.jpg$', 'photo_$1.jpg'` for capture-group renumbering, or `$_.BaseName` logic to preserve extensions while rebuilding names. Always rehearse with `Get-ChildItem *.txt | Rename-Item -NewName {...} -WhatIf`, which prints what would happen without touching a single file. Recursive jobs use `Get-ChildItem -Recurse -File`, and note the undo command here only works because the regex replacement is symmetric.
03Risk
04Undo
$ Get-ChildItem *.txt | Rename-Item -NewName { $_.Name -replace 'Vacation_','IMG_' }05Sources
- Rename-Item | Microsoft LearnEvidence: Microsoft documents Rename-Item as renaming an item in place, accepting a script block for -NewName and supporting the -WhatIf preview switch.
- Rename-Item - Rename a file - PowerShellEvidence: SS64 shows Rename-Item used with the -replace operator in a script block for bulk renaming pipelines.
Last verified: 2026-09-17 · Category: Files & Folders
06Related solutions
Use Windows Package Manager to install, search, and upgrade thousands of applications from the community repository in one command.
Understand PowerShell's execution policy scopes and set the one that lets you run your own local scripts without gutting the security model.
Robocopy is Windows' built-in robust file copier: use /MIR to keep a destination folder as an exact one-way mirror of a source, resumable and restartable.