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.

WindowsFilesTerminaldeveloperMedium risk
Run `Get-ChildItem *.txt | Rename-Item -NewName { $_.Name -replace 'IMG_','Vacation_' }` to rewrite a prefix across every file, adding `-WhatIf` first to preview.

01Command

Command
$ 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

RiskMedium risk
RequirementsPowerShell (any version); run inside the target folder and preview with -WhatIf first.
!Warning: Regex bulk renames are hard to reverse once the pattern no longer matches the new names — always run with -WhatIf first and work on a copy when experimenting.

04Undo

Undo
$ Get-ChildItem *.txt | Rename-Item -NewName { $_.Name -replace 'Vacation_','IMG_' }

05Sources

  • Rename-Item | Microsoft Learn
    Microsoft · vendor-doc · 2026-09-17
    Evidence: 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 - PowerShell
    SS64 · technical · 2026-09-17
    Evidence: 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