Greetings,
Would it be possible to create a script that would export the current user’s Outlook mailbox to a local PST file?
Thanks!
Matt
Greetings,
Would it be possible to create a script that would export the current user’s Outlook mailbox to a local PST file?
Thanks!
Matt
Hi @ntelogic,
We have asked our script developers to check and provide feedback.
Kind Regards,
PremJK
Hi @ntelogic,
We are extremely sorry to inform you that this script is not feasible ,since we don’t have any command line switch for outlook to export outlook profile as pst.
This script request is not doable.
Kind Regards,
PremJK
Scripting export of email to PST from just local Outlook profiles is tricky outside of using a paid third-party tool. If needing to export from a mailserver like exchange or Office 365, exporting to PST can be done fairly easily with powershell.
I dont know if this is helpful to you or not, but I have some scripts that will export current user outlook email folders to disk (or network location) as .msg files. Working with .msg files is not nearly as inclusive as PST, but can be an option if you only need email messages backed up. If you think this would be helpful, let me know and I can share this script.
I’ve looked into trying to improve this script to get the export to go to PST, but so far have had no luck. I can do almost everything else, including attach and import emails FROM a PST, but unable to go the other direction.
@eztech Thank you for your kind offer! Yes, we’d appreciate your sharing of the script.
@ntelogic
Roger that. Give me about a day or so, as I need to clean up the script code, make some adjustments and put into a ITSM procedure you can import easily. I’ll post back here soon!
@eztech Many thanks!
@ntelogic
Below is the script along with some documentation/instructions on how to use it and what you can configure. Hopefully its clear and understandable. The code itself is a bit messy and there is a bunch of unused/test code in there as this is something I have been testing and cobbling together, however feel free to change anything you see fit.
If you have any questions, issues or suggestions feel free to let me know. Will share anything here in case anyone else finds it useful.
Export-OutlookMessages -
Version: 0.2
SYNOPSIS
Powershell Script that connects to logged-in users outlook context to retrieve and optionally export outlook profiles and emails. This script is executed from a python script within an ITSM procedure.
Requirements
Full Description
This script provides the ability to export emails from Outlook to local disk or network location in the .MSG format. It must be run under the current user context and will connect to Outlooks default profile.
If you wish to only retrieve a list of any and all Outlook profiles or mailboxes connected, you can enable listonly mode in the configuration variables. Doing so will not perform any export.
This script can be used as a method to automatically backup emails on a local machine. It is not intended to replace email backup solutions, but can be used when backup options are limited or not available.
Another potential use case is to backup emails from an Outlook client that is no longer connected to the mail server and thus emails cannot be saved server side. An example of this is if there is an exchange crash/loss and the only copy of emails for an account are within the cached OST of an Outlook client. That use case was the main factor in the decision to create this script.
Exported emails will be put into a folder structure as follows:
NOTES
Author: EZTechhelp
IMPORTANT
This script was tested using an Outlook client connected to an Office 365 email account. While it should work for any kind of email account connected to outlook, results may vary. It is also important to understand that execution of the script may take a long time depending on the size/number of email being exported. If an error occurs on exporting a specific message (due to corruption or other factors) the script will skip the message and continue to the next one, unless an unrecoverable error occurs which will cause the script to abort. The script only reads from Outlook and performs no write attempts other than to the specified path for exportfolder. Therefore, the script should not cause any issues with or disrupt data in outlook itself.
How to Install
Connecting to Outlook Session
Current Profile Name : Outlook
Current User : Test User
Connection Type : Mapi
Exchange Connection Mode : olCachedDisconnected
Exchange Mailbox Server Name : https://outlook.office365.com/mapi/e…=xxxxx@example.com
Exchange Mailbox Server Version: 15.20.3890.28
Connecting to Outlook Session
Account Name : testuser@example.com
File Path : C:\Users estuser\AppData\Local\Microsoft\Outlook\ testuser@example.com.ost
IsOpen : True
IsCachedExchange: True
IsDataFileStore : True
Account Name : TestSharedMailAccount
File Path :
IsOpen : True
IsCachedExchange: False
IsDataFileStore : False
Connecting to Outlook Session
Connecting to Outlook Session
Name FullFolderPath UnReadItemCount
Inbox \ estuser@example.com\Inbox 918
Sent \ estuser@example.com\Inbox\Sent 0
<b>Example Output with Export</b>
Connecting to Outlook Session
Current Profile Name : Outlook
Current User : Test User
Connection Type : Mapi
Exchange Connection Mode : olCachedConnectedFull
Exchange Mailbox Server Name : https://outlook.office365.com/mapi/e…=xxxxx@example.com
Exchange Mailbox Server Version: 15.20.3890.28
Connecting to Outlook Session
Added 2 base folders
Get-OutlookFolder finished
Account Name : testuser@example.com
File Path : C:\Users estuser\AppData\Local\Microsoft\Outlook\ testuser@example.com.ost
IsOpen : True
IsCachedExchange: True
IsDataFileStore : True
Account Name : TestSharedMailbox
File Path :
IsOpen : True
IsCachedExchange: False
IsDataFileStore : False
Connecting to Outlook Session
Added 2 base folders
Filtering out folders not in main mailbox.
Remaining 1 base folders.
Get-OutlookFolder finished
Connecting to Outlook Session
Export-OutlookFolder starting…
Added 2 base folders
Filtering out folders not in main mailbox.
Remaining 1 base folders.
…Checking: \ estuser@example.com\Inbox
…Exporting \ estuser@example.com\Inbox , 19 message(s)
Export-OutlookMessage starting…
…Processing: Test Email 1
…Saving message to C:\emailexport estuser@example.com\Inbox\FROM= Support SUBJECT= Test Email 1.msg
Export-OutlookMessage completed.
Export-OutlookMessage starting…
…Processing: Test Email 2
…Saving message to C:\emailexport estuser@example.com\Inbox\FROM= Support SUBJECT= Test Email 2.msg
Export-OutlookMessage completed.
Export-OutlookMessage starting…
…Processing: Test Email 3
…Saving message to C:\emailexport estuser@example.com\Inbox\FROM= Support SUBJECT= Test Email 3.msg
Export-OutlookMessage completed.
Export-OutlookMessage starting…
…Processing: Test Email 4
…Saving message to C:\emailexport estuser@example.com\Inbox\FROM= Support SUBJECT= Test Email 4.msg
Export-OutlookMessage completed.
Export-OutlookMessage starting…
…Processing: Test Email 5
…Saving message to C:\emailexport estuser@example.com\Inbox\FROM= Support SUBJECT= Test Email 5.msg
Export-OutlookMessage completed.
Get-OutlookFolder finished
Export-OutlookFolder completed.
[20210303-Export-OutlookMessages.json|attachment](upload://7X01SG78Gd9BNiHhApywNhckofO.json) (67.4 KB)
@eztech many thanks for the script! We’ll give a run and let you know how it goes.