
📎 This article includes 2 downloadable practice files ↓
PowerShell is built into Windows and is perfect for file chores. Open it from the Start menu (type “PowerShell”) and cd into your folder, e.g. cd "C:\Reports\March".
In this article
Always preview first
Every example below uses -WhatIf, which shows what would happen without changing anything. Remove it when the preview looks right.
1. Replace text in file names
Get-ChildItem *.xlsx | Rename-Item -NewName { $_.Name -replace "Draft", "Final" } -WhatIf
2. Add today’s date to every file
$d = Get-Date -Format "yyyy-MM-dd"
Get-ChildItem *.pdf | Rename-Item -NewName { "$($_.BaseName)_$d$($_.Extension)" } -WhatIf
3. Number files in order
$i = 1
Get-ChildItem *.jpg | Sort-Object LastWriteTime | ForEach-Object {
Rename-Item $_ -NewName ("Photo_{0:D3}{1}" -f $i, $_.Extension) -WhatIf
$i++
}
{0:D3} pads numbers to three digits (001, 002…), so they sort correctly.
4. Clean messy names (spaces, brackets)
Get-ChildItem | Rename-Item -NewName { ($_.Name -replace "[\(\)\[\]]", "" -replace "\s+", "_") } -WhatIf
5. Include sub-folders
Add -Recurse to Get-ChildItem. Be extra careful and keep -WhatIf until you are sure.
⚠️ There is no Undo for renames. Copy the folder first, or log the old and new names:
Get-ChildItem | Select-Object Name, @{n="New";e={$_.Name -replace "Draft","Final"}} | Export-Csv rename-log.csv.Prefer clicking to typing? The same job in Power Automate Desktop.
Try it yourself: step by step
- Download rename-practice.zip and unzip it — you get eight files like Report Draft (1) v2.txt.
- Shift + right-click inside the folder → Open PowerShell window here (or Terminal).
- Paste the first command from rename-examples.ps1. Because of
-WhatIfit only prints “What if: Performing the operation Rename File…”. - Remove
-WhatIfand run it for real — “Draft” becomes “Final”. - Run the “clean messy names” command: brackets vanish and spaces become underscores.
📎 Practice files for this article
- 🗂️8 messy practice files (zip)Names with spaces, brackets and 'Draft' u2014 safe to experiment on.⬇ ZIP · 1 KB
- 🖥️PowerShell examples (.ps1)Every command from the article, with -WhatIf preview.⬇ PS1 · 418 B
Free to use for learning. Files with macros (.bas) are plain text — import them with Alt+F11 → File → Import File, and always test on a copy.