Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # STEP 1
- ###################################################################
- # To capture existing PSTs to CSV
- # Open Outlook with the OLD profile
- # IMPORTANT: Run this Code in the "x86" version of Powershell ISE
- ###################################################################
- mkdir c:\temp -ErrorAction SilentlyContinue -WarningAction SilentlyContinue
- Add-type -assembly "Microsoft.Office.Interop.Outlook" | out-null
- $outlook = New-Object -comObject Outlook.Application
- $PSTs = @($outlook.Session.Stores | where {$_.FilePath -like "*.pst"} | Select DisplayName, FilePath)
- $PSTCount = $PSTs.count
- If ($PSTCount -gt 0)
- {cls
- $PSTs | Export-Csv c:\temp\PSTs.csv
- write-host "Found $PSTCount PSTs and Exported their file path to C:\temp\PSTs.csv" -ForegroundColor cyan}
- else
- {cls
- write-host "No PSTs found attached to this profile" -ForegroundColor Cyan}
- Read-Host "DONE - Press any key to exit..."
- Break
- ###################################################################
- # STEP 2
- ###################################################################
- # To attach all PSTs to the new profile
- # Open Outlook with the NEW profile
- # IMPORTANT: Run this Code in the "x86" version of Powershell ISE
- ###################################################################
- Add-type -assembly "Microsoft.Office.Interop.Outlook" | out-null
- $outlook = new-object -comobject outlook.application
- $namespace = $outlook.GetNameSpace("MAPI")
- $PSTs = import-csv c:\temp\PSTs.csv
- ForEach ($PST in $PSTs)
- {
- $currentPST = $PST.FilePath
- write-host "Attaching: $currentPST" -ForegroundColor Cyan
- $namespace.AddStore($PST.FilePath)
- write-host "Done : $currentPST" -ForegroundColor Green}
- Read-Host "DONE - Press any key to exit..."
- Break
- ###################################################################
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement