0

I am ingesting PST into Enterprise vault and I have some that fail. In some cases I have to recreate the PST file by opening it in Outlook and exporting the contents to a new PST file.

Is it possible to do this with powershell? I am creating the new PST from an existing PST and not from Exchnage so, as far as I know, the new-mailboxexportrequest wont work

TIA

Andy

Andy White
  • 65
  • 3
  • 9
  • if i understand you right, you already have a pst file in the profile and you want to export it? why do you need to export it at all? Just copy it to a new file... – Avshalom Aug 04 '15 at 10:36
  • The original PST has some kind of corruption as it won't import into Enterprise Vault. If I open it and export it to a new PST file then that imports fine. I am looking for a quicker way of doing it as i have a lot of PST files to go through – Andy White Aug 04 '15 at 10:53

1 Answers1

1

You can use the Outlook Interop (ComObject) to interact with outlook programmatically and add a new PST file Store

After that Copy all the folders from your old PST into it.

I added a comments to each step so you can understand what it doing...

Of course it's your job to check the reliabilty of this process for missing items and so, here it is:

$NewPSTFilePath = "C:\PST\Backup.pst" ## add Your new PST file name path

$outlook = New-Object -ComObject outlook.application
$namespace  = $Outlook.GetNameSpace("MAPI")

$OLDStore = $namespace.Stores | Select -First 1 ## get your old PST Store (select the first 1 only)
$NameSpace.AddStore($NewPSTFilePath) ## Add the new PST to the Current profile
$NEWStore = $namespace.Stores | ? {$_.filepath -eq $NewPSTFilePath} ## Get the New Store

$OLDPSTFolders = $OLDStore.GetRootFolder().Folders ## Get the list of folders from the PST
foreach ($folder in $OLDPSTFolders)
{
"Copy $($folder.name)"
[void]$folder.CopyTo($NEWStore)
}

Note:

The script use your default outlook profile, to connect to a differnet profile, add the line $namespace.Logon("OtherProfileName") after the $namespace = $Outlook.GetNameSpace("MAPI")

Avshalom
  • 8,657
  • 1
  • 25
  • 43
  • Looks good....for $OLDStore can I specify the file/location rather than it looking for it? I am copying the PST files to a specific folder so I can work on them locally rather than over a server share – Andy White Aug 04 '15 at 12:03