PowerShell: Convert ConversationHistory from UserCreated to a Default Folder


Time for a new article, this time talking about Conversation History Retention Policies.

I have recently been working with some customers who reported that Retention Policies applied to Conversation History would not get applied. After a lengthily investigation it appeared the issue was due to the "Conversation History" folder was not of type "CommunicatorHistory" but rather "User Created".

This folder is usually created by Lync or Skype for Business the first time the client connects to the mailbox.

 

This is how a broken Conversation History folder looks like:

Get-Mailbox Blog_User | Get-MailboxFolderStatistics | ?{$_.Name -like "Conversation*"} | Select Name, FolderType

Name                                   FolderType
----                                   ----------
Conversation History                   User Created

 

This is how a correctly configured Conversation History folder looks like:

Get-Mailbox Blog_User | Get-MailboxFolderStatistics | ?{$_.Name -like "Conversation*"} | Select Name, FolderType

Name                                   FolderType
----                                   ----------
Conversation History                   CommunicatorHistory

 

What is it doing then?

This script check the presence of the property 0x35E90102 in the Inbox. This MAPI property contains a link to the UniqueId of the Conversation History folder.

When this property is populated with the correct UniqueId, the Conversation History folder type appears as the well-known FolderType, oppositely if this property has an incorrect UniqieId (i.e. the Conversation History folder has been deleted and recreated) or the property is missing (has never been set or has been accidentally deleted) then the folder would appear as User Created.

 

In this very last scenario, Retention Policies targeting the Conversation History would not be correctly applied and items in the folder would not be aged out.

Overall, the work stream is the following:

  1. Locate the EWS Managed API location (overridden if -EWSManagedApiPath "<location>" is specified)
  2. Locate the EWS endpoint (overridden if -EwsUrl "<url>" is specified)
  3. Connect to the target mailbox(es) via EWS (can leverage Owner Logon, Delegate Access or Impersonation)
  4. Retrieve the mailbox folders data (Inbox and Conversation History)
  5. Update the property  0x35E90102 (unless -Simulate is used)

 

The script is capable of processing a list of mailboxes provided either via a CSV or a list of comma separated email addresses as well as a single mailbox, given its primary SMTP address or the logged-on user mailbox if the -Mailbox parameter is omitted.

 

How to run it?

This is rather easy.

The script comes with detailed help documentation which can be invoked directly via PowerShell.

Get-Help .\Convert-ConvHistoryFromUserCreated.ps1 -Detailed

 

Please note that the "Mailbox" parameter expects an email address, this can be the PrimarySmtpAddress, the UserPrincipalName or the WindowsEmailAddress.

Do not try using an alias or a mailbox GUID as these would not work.

 

Examples? Here you go.

Here an end-user would run the script on his own, without admin intervention. The script is run from a Domain-Joined client as the logged-on user email address is retrieved via a query to AD.

.\Convert-ConvHistoryFromUserCreated.ps1 -LogFile .\LogFile.txt

 

In this example you can see the administrator Admin@Contoso.com is running the script against Test@Contoso.com. At this time Full Access permission is leveraged.

$Cred = Get-Credential
.\Convert-ConvHistoryFromUserCreated.ps1 -Mailbox "Test@Contoso.com" -Credentials $Cred -LogFile .\LogFile.txt

 

In this other example the administrator Admin@Contoso.com is still running the script against Test@Contoso.com. At this time however Application Impersonation is leveraged.

$Cred = New-Object System.Management.Automation.PSCredential -ArgumentList ('Admin@Contoso.com'), (ConvertTo-SecureString -AsPlainText 'AdminPassword' -Force)
.\Convert-ConvHistoryFromUserCreated.ps1 -Mailbox "Test@Contoso.com" -Credentials $Cred -Impersonate -LogFile .\LogFile.txt

 

In this other example the administrator Admin@Contoso.com is still will run the script against a list of users. At this time Application Impersonation is leveraged as it enables the administrator to access any mailbox in scope without assigning individual mailbox permissions.

$Cred = Get-Credential -UserName Admin@Contoso.com
.\Convert-ConvHistoryFromUserCreated.ps1 -Mailboxes "Test@Contoso.com","Other@Contoso.com" -Credentials $Cred -Impersonate -LogFile .\LogFile.txt

 

In the last example the logged on user will run the script against a list of users stored in a CSV file. Again, Application Impersonation is used. Administrative credentials can be provided, as demonstrated in the previous example if desired. The CSV File may have multiple comuns, however it must contain a column named PrimarySMTPAddress in order for the script to process the mailboxes.

.\Convert-ConvHistoryFromUserCreated.ps1 -CSV "C:\TEMP\UserList.csv" -Impersonate -LogFile .\LogFile.txt

 

If you have to troubleshoot the script you can avail of the -Verbose switch which will display additional information on screen. If you wish to investigate EWS failures instead you can use the -Trace switch which will print on screen the HTTP requests and responses exchanged between the client and the server.

 

The sample scripts.

Here you can download the script: Convert-ConvHistoryFromUserCreated.

 

Comments (0)

Skip to main content