PowerShell Rename Files in Bulk: Rename-Item Examples

A folder of photos named IMG_4523.jpg through IMG_4987.jpg. Log files without dates in the name. Configuration files that need a server name prepended. These are everyday PowerShell rename files bulk scenarios, and a few lines of PowerShell handles what would otherwise take an hour of manual renaming. This guide covers single and bulk renaming, pattern-based substitution, date prefixing, sequential numbering, and the all-important -WhatIf preview.
Rename a Single File
Use Rename-Item to rename one file. It only changes the name — not the location:
# Simple rename
Rename-Item -Path 'C:\Logs\old-name.log' -NewName 'new-name.log'
# Rename preserving the extension
$file = Get-Item 'C:\Docs\report.docx'
Rename-Item -Path $file.FullName -NewName "final-$($file.Name)"
# Rename using a variable for the new name
$newName = 'deployment-2026-05-04.log'
Rename-Item -Path 'C:\Logs\deploy.log' -NewName $newName
Note: Rename-Item only accepts a filename for -NewName, not a full path. To move and rename simultaneously, use Move-Item instead.
Bulk Rename with ForEach-Object
To rename multiple files, pipe from Get-ChildItem to ForEach-Object:
# Add prefix to all .log files
Get-ChildItem 'C:\Logs' -Filter '*.log' | ForEach-Object {
Rename-Item -Path $_.FullName -NewName "archive_$($_.Name)"
}
# Convert all filenames to lowercase
Get-ChildItem 'C:\Downloads' -Filter '*.txt' | ForEach-Object {
Rename-Item -Path $_.FullName -NewName $_.Name.ToLower()
}
# Before: app.log, error.log, debug.log
# After: archive_app.log, archive_error.log, archive_debug.log
Always preview with -WhatIf before running bulk renames. A pattern that looks correct can match more files than intended.
Replace Part of Filename with -replace
Use the -replace operator to swap part of a filename:
# Replace 'DRAFT' with 'FINAL' in all filenames
Get-ChildItem 'C:\Docs' -Filter '*DRAFT*' | ForEach-Object {
$newName = $_.Name -replace 'DRAFT', 'FINAL'
Rename-Item -Path $_.FullName -NewName $newName
}
# Remove spaces from filenames (replace with underscores)
Get-ChildItem 'C:\Downloads' | Where-Object { $_.Name -like '* *' } | ForEach-Object {
$newName = $_.Name -replace ' ', '_'
Rename-Item -Path $_.FullName -NewName $newName
}
# Remove version numbers from filenames using regex
Get-ChildItem 'C:\Installers' -Filter '*.exe' | ForEach-Object {
$newName = $_.Name -replace '_v\d+\.\d+', ''
if ($newName -ne $_.Name) {
Rename-Item -Path $_.FullName -NewName $newName
}
}
# Before: Report DRAFT v2.docx
# After: Report_FINAL.docx
Add Date Prefix to Filenames
Prepending today’s date to log files or backup files makes them sortable by creation time:
$today = Get-Date -Format 'yyyy-MM-dd'
$folder = 'C:\Logs\Daily'
Get-ChildItem $folder -Filter '*.log' | ForEach-Object {
$newName = "${today}_$($_.Name)"
Rename-Item -Path $_.FullName -NewName $newName -WhatIf # Remove -WhatIf when ready
}
What if: Performing the operation "Rename File" on target
"Item: C:\Logs\Daily\app.log NewName: 2026-05-04_app.log".
What if: Performing the operation "Rename File" on target
"Item: C:\Logs\Daily\error.log NewName: 2026-05-04_error.log".
The ISO date format (yyyy-MM-dd) sorts correctly both alphabetically and chronologically, making it ideal for file prefixes.
Sequential Numbering
Rename files with sequential numbers — useful for photos or documents that need a defined order:
$photos = Get-ChildItem 'C:\Photos\Vacation' -Filter '*.jpg' | Sort-Object LastWriteTime
$counter = 1
foreach ($photo in $photos) {
$paddedNum = $counter.ToString().PadLeft(4, '0')
$newName = "Vacation_${paddedNum}$($photo.Extension)"
Rename-Item -Path $photo.FullName -NewName $newName
$counter++
}
# Before: IMG_4523.jpg, DSC_8721.jpg, photo.jpg
# After: Vacation_0001.jpg, Vacation_0002.jpg, Vacation_0003.jpg
Sort by LastWriteTime or CreationTime before numbering to control the order. Zero-pad the number with PadLeft(4,'0') so alphabetic sorting matches numeric sorting.
Preview Changes with -WhatIf
Use -WhatIf to see what would be renamed without making any changes:
Get-ChildItem 'C:\Docs' -Filter '*.docx' | ForEach-Object {
$newName = $_.Name -replace 'Proposal', 'Contract'
Rename-Item -Path $_.FullName -NewName $newName -WhatIf
}
What if: Performing the operation "Rename File" on target
"Item: C:\Docs\Project_Proposal.docx NewName: Project_Contract.docx".
What if: Performing the operation "Rename File" on target
"Item: C:\Docs\2026_Proposal.docx NewName: 2026_Contract.docx".
Review the output carefully. When the list looks right, remove the -WhatIf flag and run again.
Common Errors and Fixes
-
Name collision if target name already exists: Renaming to a name that already exists in the same folder throws an error. Add a check:
if (-not (Test-Path (Join-Path $_.DirectoryName $newName))) { Rename-Item ... }to skip files that would collide. -
-WhatIf not supported on some providers: On non-filesystem providers (like registry or certificate stores),
-WhatIfmay not work as expected. Always verify in a test directory before running bulk renames on production data.
Related Cmdlets / See Also
Wrapping Up
Bulk renaming with PowerShell is a pipeline: Get-ChildItem | ForEach-Object { Rename-Item }. Use -replace for pattern substitutions, Get-Date -Format for date prefixes, and zero-padded counters for sequential numbering. Always preview with -WhatIf first. Your next step: apply the date-prefix pattern to normalize a log folder that currently has inconsistently named files.


