Share via


Retention: Which Retention Policy Tag is applied to message - EWS way

In my last post I showed how to check which Retention Policy Tag is applied to the item within user's mailbox. In this post I'm going to show how same information can be checked using EWS. Compared to Get-StoreQuery way, using EWS is more convenient if you are using Office 365 mailboxes since you won't have access to Get-StoreQuery command .

In this demonstration I'll use EWS PowerShell module I wrote while back. Module is still under developement. Please note, using commands and modules from this post are at your own risk.

Download and install module:

 Invoke-Expression -Command (Invoke-WebRequest -Uri "https://raw.githubusercontent.com/IvanFranjic/XEws/master/InstallXEwsModule.ps1")

Create Ews session:

 Import-EwsSession -EmailAddress "user@domain.com" -Password (ConvertTo-SecureString -AsPlainText -Force -String "pass") -EwsEndpoint "https://mail.domain.com/ews/exchange.asmx"

( If you omit parameter -EwsEndpoint, autodiscover will be used for locating correct endpoint )

Retreive message from desired folder and get retention tag:

 $folder = Get-EwsFolder -FolderName "MyStuff"
Get-EwsItem -FolderRoot $folder.Id | select ConversationTopic, *Archive*, *Retention*
 
ConversationTopic ArchiveTag                           RetentionDate
----------------- ----------                           -------------
Important report  3afbf723-8f69-4a3d-8fdf-7254278dd560 3.5.2016. 12:43:20
Retention tag     3afbf723-8f69-4a3d-8fdf-7254278dd560 1.5.2016. 14:22:50
  
    
Get-RetentionPolicyTag 3afbf723-8f69-4a3d-8fdf-7254278dd560
 
Name                      Type                      Description
----                      ----                      -----------
Personal 60 Day Archive   Personal                  Managed Content Settings

Ews call returns .Net guid representation of the tag so result can be feeded directly in Get-RetentionPolicyTag Exchange cmdlet.