Advertisement
Guest User

Export PSTs FilePaths to CSV and the attach to a new profile

a guest
Nov 8th, 2018
332
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # STEP 1
  2.  
  3. ###################################################################
  4. #  To capture existing PSTs to CSV
  5. #  Open Outlook with the OLD profile
  6. #  IMPORTANT: Run this Code in the "x86" version of Powershell ISE
  7. ###################################################################
  8.  
  9. mkdir c:\temp -ErrorAction SilentlyContinue -WarningAction SilentlyContinue
  10. Add-type -assembly "Microsoft.Office.Interop.Outlook" | out-null
  11. $outlook = New-Object -comObject Outlook.Application
  12. $PSTs = @($outlook.Session.Stores | where {$_.FilePath -like "*.pst"} | Select DisplayName, FilePath)
  13. $PSTCount = $PSTs.count
  14.  
  15. If ($PSTCount -gt 0)
  16. {cls
  17. $PSTs | Export-Csv c:\temp\PSTs.csv
  18. write-host "Found $PSTCount PSTs and Exported their file path to C:\temp\PSTs.csv" -ForegroundColor cyan}
  19. else
  20. {cls
  21. write-host "No PSTs found attached to this profile" -ForegroundColor Cyan}
  22.  
  23. Read-Host "DONE - Press any key to exit..."
  24. Break
  25.  
  26. ###################################################################
  27.  
  28.  
  29. # STEP 2
  30.  
  31. ###################################################################
  32. #  To attach all PSTs to the new profile
  33. #  Open Outlook with the NEW profile
  34. #  IMPORTANT: Run this Code in the "x86" version of Powershell ISE
  35. ###################################################################
  36.  
  37. Add-type -assembly "Microsoft.Office.Interop.Outlook" | out-null
  38. $outlook = new-object -comobject outlook.application
  39. $namespace = $outlook.GetNameSpace("MAPI")
  40. $PSTs = import-csv c:\temp\PSTs.csv
  41.  
  42. ForEach ($PST in $PSTs)
  43. {
  44. $currentPST = $PST.FilePath
  45. write-host "Attaching: $currentPST" -ForegroundColor Cyan
  46. $namespace.AddStore($PST.FilePath)
  47. write-host "Done     : $currentPST" -ForegroundColor Green}
  48.  
  49. Read-Host "DONE - Press any key to exit..."
  50. Break
  51.  
  52. ###################################################################
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement