• Happy holidays, folks! Thanks to each and every one of you for being part of the Tom's Hardware community!

Script to load and upload pst file

ScienceMySon

Honorable
Jan 21, 2015
54
0
10,530
Hi guys,

Any powershell wizards here ?

A friend of mine is using Outlook 2010. We are searching for a script to mount and unmount just 1 pst file (An archive)

Anybody can help with this?
 
mount:
Code:
$Outlook = new-object -com outlook.application 
$Namespace = $Outlook.getNamespace("MAPI")

$PSTtoAdd = "c:\test\pst.pst"

$namespace.AddStore($PSTtoAdd)

unmount:
Code:
$Outlook = new-object -com outlook.application 
$Namespace = $Outlook.getNamespace("MAPI")

$PSTtoDelete = "c:\test\pst.pst"
$PST = $namespace.Stores | ? {$_.FilePath -eq $PSTtoDelete}
$PSTRoot = $PST.GetRootFolder()

$PSTFolder = $namespace.Folders.Item($PSTRoot.Name)
$namespace.GetType().InvokeMember('RemoveStore',[System.Reflection.BindingFlags]::InvokeMethod,$null,$namespace,($PSTFolder))