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:

Path,NewAlias
F:\Export\fredb.pst,fred.bloggs.pst
F:\Export\DSaster.pst,derdrie.saster.pst

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!)

2 comments:

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.