How to get the list of emails added to a retention policy in Purview?

Dmitriy Kolesnikov 11 Reputation points
2024-12-23T18:22:59.7766667+00:00

We have created a few retention policies for Microsoft Purview. Each policy is applied to many specific mailboxes (100 mailboxes max). Is there a way to get the list of mailboxes added to each policy?

The Get-RetentionCompliancePolicy command shows policy properties, including the ExchangeLocation field (in truncated view {account1, account 2, ...}). How to get the list of all accounts from that attribute?

Microsoft Purview
Microsoft Purview
A Microsoft data governance service that helps manage and govern on-premises, multicloud, and software-as-a-service data. Previously known as Azure Purview.
1,329 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Ganesh Gurram 3,025 Reputation points Microsoft Vendor
    2024-12-23T22:59:59.33+00:00

    Hello @Dmitriy Kolesnikov

    Thanks for the question and using MS Q&A platform.

    To retrieve the list of mailboxes associated with each retention policy in Microsoft Purview, you can use PowerShell commands to extract and format the information from the Get-RetentionCompliancePolicy command. The ExchangeLocation field contains the mailboxes, but it may be truncated in the output.

    Here are steps to Retrieve Full List of Mailboxes for a Retention Policy:

    Open PowerShell - Make sure you have the necessary permissions, and the Exchange Online Management module installed.

    Connect to Exchange Online - If you haven't already connected to your Exchange Online environment, you can do so with the following command:

    Connect-ExchangeOnline -User PrincipalName <your-admin-username>
    

    Retrieve Retention Policies - Use the Get-RetentionCompliancePolicy command to get the retention policies and their properties.

    $policies = Get-RetentionCompliancePolicy
    

    Extract Mailboxes - Loop through each policy and extract the ExchangeLocation field. You can use the -ExpandProperty parameter to get the full list of mailboxes.

    powershellVerifyOpen In EditorRunCopy code
    Explain
    1foreach ($policy in $policies) {
    2    $policyName = $policy.Name
    3    $mailboxes = $policy.ExchangeLocation -join ", "
    4    Write-Output "Policy Name: $policyName"
    5    Write-Output "Mailboxes: $mailboxes"
    6    Write-Output "-----------------------------"
    7}
    

    Hope this helps. Do let us know if you any further queries.


  2. Ganesh Gurram 3,025 Reputation points Microsoft Vendor
    2025-01-07T00:54:30.8333333+00:00

    @Dmitriy Kolesnikov - I'm glad that you were able to resolve your issue and thank you for posting your solution so that others experiencing the same thing can easily reference this! Since the Microsoft Q&A community has a policy that "The question author cannot accept their own answer. They can only accept answers by others ", I'll repost your solution in case you'd like to accept the answer

    Ask: How to get the list of emails added to a retention policy in Purview?

    Solution: The problem was fixed by using the below code, which leverages the "DefinitionDetail" parameter to gather the required data.

    $exchangeObjects = Get-RetentionCompliancePolicy -Identity $policyName -DistributionDetail | Select-Object -ExpandProperty ExchangeLocation          foreach ($exObject in $exchangeObjects) {                      $outputEx += [PSCustomObject]@{             "Policy Name" = $policyName             "Mailbox"     = $exObject.Name             }         }
    

    If I missed anything please let me know and I'd be happy to add it to my answer, or feel free to comment below with any additional information. 

    If you have any other questions, please let me know. Thank you again for your time and patience throughout this issue. 

     

    Please don’t forget to Accept Answer and Yes for "was this answer helpful" wherever the information provided helps you, this can be beneficial to other community members.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.