Powershell to move pst files

I have been using a tool from Quest (GroupWise Migrator for Exchange) to migrate 7,500+ users/resources into Exchange 2007.

Part of the migration takes all of the offline archives in Groupwise (stored in the home folder of users) and converts them to PST files.

The result is a bunch of pst files that are named userid.pst, by that I mean if the user was jsmith, the pst would be called jsmith.pst

In additon, the Quest tool drops all the files into folders reflective to the groupwise domain name and groupwise postoffice. So it the groupwise domain was called DOM and the post office was called POST, and I told the quest tool to start shoving things in the c:\archivedump folder, then the pst file for jsmith would be c:\archivedump\DOM\POST\jsmith.pst

Ultimately, i need to get this file to jsmith’s home network share under \OutlookArchive and name it Migrated.pst

Time for PowerShell

First I found out that in order to get jsmith out of reading jsmith.pst, i needed a powershell extension.

I called this file My.Types.ps1xml and the contents look like this

<Types>
<Type>
<Name>System.IO.FileInfo</Name>
<Members>
<ScriptProperty>
<Name>Basename</Name>
<GetScriptBlock>
$this.Name.Remove($this.Name.Length – $this.Extension.Length);
</GetScriptBlock>
</ScriptProperty>
</Members>
</Type>
</Types>

Then i needed to run from the powershell command

Update-TypeData My.Types.ps1xml

I also added this to my script seen below, incase i forget to add it upon starting powershell later on.

To suppress errors i added

The powershell script to move the pst files, as described above is this:  $ErrorActionPreference = “SilentlyContinue”
$ErrorActionPreference = “SilentlyContinue”
# The My.Types.ps1xml is an extenstion to recognize the $_.basename, the filename w/o extension
Update-TypeData My.Types.ps1xml
$Path = “c:\Archives\”

foreach ($file in Get-Childitem $Path -recurse -force)
{if ($file.extension -eq “.pst”)
{
$user= $file.basename
New-item \\server1\home\$user\OutlookArchive -type directory
Move-Item $file.fullname \\server1\home\$user\OutlookArchive\Migrated.pst
}
}
Advertisements

About Mike

owner of blog
This entry was posted in PowerShell. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s