«

»

Jan 23

PowerShell Basic – Quick Mass Filename Rename

Just a quick snip of PowerShell for renaming files or folders in mass.

Get-ChildItem -Recurse | Rename-Item -NewName {$_.Name -replace 'OLDNAME','NEWNAME'}


Get-ChildItem returns all the files in the current directory. The -Recurse parameter also returns files and folders in any subfolders.

Here is the output of Get-ChildItem from my current directory.
PS-Get-ChildItem

I want to rename all the files replacing the part of the name containing “7005N” with “B05328”. The Rename-Item -NewName gets the name from Get-ChildItem and performs a replace to replace the part of the filename matching 7005N with B05328 in the current folder and any subfolders.

PS-Rename-Item

Quick and handy.

About the author

vHersey

Hersey Cartwright is an IT professional with extensive experience designing, implementing, managing, and supporting technologies that improve business processes. Hersey is Solutions Architect for SimpliVity covering Virginia, Washington DC, and Maryland. He holds the VMware Certified Design Expert (VCDX-DV #128) certification. Hersey actively participates in the VMware community and was awarded the VMware vExpert title in 2016, 2015, 2014, 2013, and 2012. He enjoys working with, teaching, and writing about virtualization and other data center technologies. Follow Hersey on Twitter @herseyc

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

one × four =