Save Outlook emails in .msg using PowerShell - aaqibwani/M365 GitHub Wiki
Download and run https://github.com/aaqibwani/M365/blob/main/SaveAsMsgV2.ps1
You can simply run the script without any parameters. It will prompt to select an Outlook folder and then it will ask for the output folder where you want to store the msg files.
Note: All files in the selected Outlook folder will be saved in .msg format. If you want to save specific files, create a custom folder and move all emails to that custom folder.
.\SaveAsMsgV2.ps1 
.\SaveAsMsgV2.ps1 -OutputFolderPath "C:\SavedEmails\MyProject
If you get the below error when trying to save emails, it means that Outlook is set to deny programmatic access to 'Save As' from any program. "Error saving email '<>': Operation aborted (0x80004004 (E_ABORT))"
To verify the block, open regedit and navigate to: Computer\HKEY_CURRENT_USER\Software\Policies\Microsoft\office\16.0\outlook\security OR Computer\HKEY_USERS<SID>\Software\Policies\Microsoft\office\16.0\outlook\security


To fix this, you need to update the value of promptoomsaveas from 0 (Automatically Deny) to 2 (Automatically Allow). But since this will most likely be pushed from a GPO when using an enterprise connected machine, you will need to update the GPO settings under the Outlook ADMX file or Intune as applicable:
GPO:
Intune:
