Rename PowerShell Scripts

by Jul 26, 2012

Rename-Item can easily batch-rename large numbers of files, simply by piping file objects into it. Here is a sample that finds all PowerShell script files in your home folder and checks whether they contain the phrase "Untitled" followed by a number. If so, the name is replaced by that number plus "_Untitled Script – Check":

Dir $home *.ps1 -Recurse | Rename-Item -NewName { $_.Name -replace 'Untitled(\d{1,})', '$1_Untitled Script - Check' }

Twitter This Tip! ReTweet this Tip!