-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathexport-PFdata.ps1
37 lines (29 loc) · 2.67 KB
/
export-PFdata.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<#
This script is meant to export a public folder from outlook into a PST.
It requires that you have outlook installed on a machine AND have a configured exchange profile.
last updated: 05/14/2013 Gil
#>
param ($pstPath = "C:\temp", $topFolderName="GilsPFs")
#define location of PST
$pstFQDN = $pstPath + "\" + $topFolderName + ".pst"
#Open up outlook
[Reflection.Assembly]::LoadWithPartialname("Microsoft.Office.Interop.Outlook") | out-null
$Outlook = New-Object -comobject Outlook.Application
$olFolders = "Microsoft.Office.Interop.Outlook.OlDefaultFolders" -as [type]
$namespace = $Outlook.GetNameSpace("MAPI")
#add pst path to outlook
$namespace.AddStore($pstFQDN)
$pstFolder = $namespace.Session.Folders.GetLast()
#Grab the PFs and save it
$folders = $namespace.getDefaultFolder($olFolders::olPublicFoldersAllPublicFolders)
$pfFolders = $folders.Folders.Item($domain)
$pfFolders.CopyTo($pstFolder)
$pstFolder.Name = "$domain PF dump"
#Attach PST to new profile
$namespace.AddStore($pstFQDN)
$pstFolder = $namespace.Session.Folders.GetLast()
#Grab content from PST
$folders = $namespace.getDefaultFolder($olFolders::olPublicFoldersAllPublicFolders)
$pfFolders = $folders.Folders.Item($domain) #this should probably be root.
$pstFolder = $pstFolder.Folders.Item($domain)
$pstFolder.CopyTo($pfFolders)