Copying PST files using powershell

I needed to copy a bunch of PST files to a network location, but the original file name and folder structure was a bit of a mess.  eg:

e:\archive\user1.pst

e:\archive\user2.pst

e:\archive\user1\user1.pst

e:\archive\user1\user1archive.pst

e:\archive\user3\user1.ps1

I didn’t actually care about the folder structure, all I wanted was the pst files themselves, as such i could rename them, as long as the username was easily identifiable.  So I decided to append a random string to the file name.

I had a list of the pst files in a txt document, so the script:

$ListOfPSTFiles=get-content .\pstfilesToCopy.txt

foreach ($strPSTFile in $ListOfPSTFiles)

{

    $RandomIdentifier=Get-Random

    $PSTFile=[System.IO.FileInfo]$strPSTFile

    $Destination="\\archive\PSTFiles\"+$PSTFile.BaseName+" - "+$RandomIdentifier+$PSTFile.Extension

    copy-item $PSTFile -Force -Destination $Destination

    $log=$strPSTFile+" has been copied to "+$Destination

    $log | out-file c:\logs\pstcopy.txt -Append

}

Leave a Reply

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