Thursday 14 April 2011

Renaming files using PowerShell and a CSV

During a migration of users from an outside organisation into ours, we had to bring across all their exchange data using exmerge.

The problem was, all their exported PST's were named incorrectly.

So, a quick CSV was knocked up with two columns.
Column 1 = Path and current file name
Column 2 = New file name

Add a header at the top of the CSV to give something like this:


Then use the following PowerShell line:
import-csv c:\PSTImport.csv | foreach {rename-item -path $_.path -newname $_.newalias}
Job done, one nicely renamed folder of PST files ready to exmerge (shame we're still on Exchange 2003!)


Anonymous said...

Steve! This short and sweet script could end up being incorporated into a major workflow I've imagined for months! And i owe you many thanks! This inspires me to share all the great ideas I've been able to make a script reality due to the help of other generous scripting guys like you.

Anonymous said...

Thanks for this. I stumbled across this after writing some ugly script for importing an XLSX and using a 2 dimensional array to rename files.. You saved me hours lol.

Anonymous said...

You're a life saver, just saved me renaming 150 directories by hand.

Much appreciated:)

Anonymous said...

Brilliant, this just saved me from manually renaming over 1500 documents. This is awesome.

Missy's Graphical Adventures said...

still saving us time even in almost 2017

jonathan987 said...

This is a great article. You can use this technique. Beside this- I have a software for bulk rename. My software works with all platform. For checking my software go to google and type- BatchRenameFiles Tool. Check the first result.

Anonymous said...

Thanks - this is an excellent and simple solution to a problem i have been struggling with for several hours