-2

I have to create archive (.pst file) for mailbox in Outlook. I use an exchange server 2016. If i do the "microsoft way" (https://support.microsoft.com/en-us/office/archive-items-manually-ecf54f37-14d7-4ee3-a830-46a5c33274f6) i always find mails that aren't transfert to the archive. Cached Exchange Mode are turn off.

I wish to find a way with powershell to access Outlook and the mail box. I want to copy all folders and subfolders name, their hierarchy, to create them on my archive.pst

Then, i want to find all mail prior to a specific date, and copy each mail on the right folder.

Thank to the post here : Powershell - Read and Move mails to archive folder the function "Get-OutlookInBox" could give me mails, but only it seems on Inbox, not the others folders.

Can anyone tell me how to do this ?

Thank in advance

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45

2 Answers2

0

Posts you are referring to use PowerShell scripts that automate Outlook. The OOM has access to the local data only.

Instead, you can use EWS, see Explore the EWS Managed API, EWS, and web services in Exchange for more information. But EWS is discontinued, so now Graph API is the best and valid approach for that, read more about that in the Outlook mail API overview article.

Then, i want to find all mail prior to a specific date, and copy each mail on the right folder.

Here you are free to use a powershell script which searches for items that correspond to your conditions. The Find/FindNext or Restrict methods can help with such tasks in Outlook:

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
  • EWS is **not** discontinued. It is fully supported, but there will be no further development except for the security fixes. – Dmitry Streblechenko Feb 08 '22 at 17:45
  • MS recommends using Graph API over EWS. In August 2018, MS announced that they were no longer going to actively invest in Exchange Web Services (EWS) APIs for Exchange Online. They also gave a strong recommendation to start migrating to Microsoft Graph for Exchange Online data access. Support for some APIs will no longer exist after March 31, 2022. See [Upcoming API Deprecations in Exchange Web Services for Exchange Online](https://techcommunity.microsoft.com/t5/exchange-team-blog/upcoming-api-deprecations-in-exchange-web-services-for-exchange/ba-p/2813925). – Eugene Astafiev Feb 08 '22 at 18:11
0

I try to use that function :

Function Get-OutlookInBox 
{ 
Add-type -assembly "Microsoft.Office.Interop.Outlook" | out-null 
$olFolders = "Microsoft.Office.Interop.Outlook.olDefaultFolders" -as [type]  
$outlook = new-object -comobject outlook.application 
$namespace = $outlook.GetNameSpace("MAPI") 
$folder = $namespace.getDefaultFolder($olFolders::olFolderInBox) 
$folder.items | Select-Object Subject, UnRead, ReceivedTime, SenderName #* # Subject, UnRead, ReceivedTime, SenderName 
}

But it only analyse the Inbox folder, not the others. And i don't have an object refering to the folder

Maybe i don't use the right code ?