inactive mailboxes

Glenn Maxwell 11,981 Reputation points
2024-12-26T16:40:30.9166667+00:00

Hi All,

I have a few inactive mailboxes under a retention policy in the Microsoft Purview Portal (Data Lifecycle Management → Retention policies → RP01). Let's say the policy is named RP01, and its GUID is u98k89mn-9876-ht68-mjki-kj78oophgy768.

Exporting Inactive Mailboxes to CSV:

I want to export all my inactive mailboxes with the fields DisplayName, PrimarySMTPAddress, and WhenSoftDeleted to a CSV file. Is the following syntax correct?

Get-Mailbox -InactiveMailboxOnly -ResultSize Unlimited | Select-Object DisplayName, PrimarySMTPAddress, WhenSoftDeleted | Export-Csv C:\inactivemailboxes.csv -NoTypeInformation

Removing Email Addresses from the Retention Policy:

I have inactive mailboxes email addresses listed in a CSV file, and I want to remove them from the retention policy. Is the following syntax correct? i have csv file in the below format.

users 
user1@contoso.com 
user2@contoso.com

Import-Csv C:\mailboxes.csv | ForEach-Object { 
Set-Mailbox -Identity $_.users -ExcludeFromOrgHolds u98k89mn-9876-ht68-mjki-kj78oophgy768}

Microsoft Exchange Online
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,304 questions
Microsoft Exchange Online Management
Microsoft Exchange Online Management
Microsoft Exchange Online: A Microsoft email and calendaring hosted service.Management: The act or process of organizing, handling, directing or controlling something.
4,657 questions
Microsoft Exchange Hybrid Management
Microsoft Exchange Hybrid Management
Microsoft Exchange: Microsoft messaging and collaboration software.Hybrid Management: Organizing, handling, directing or controlling hybrid deployments.
2,178 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,587 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Alex Zhang-MSFT 3,155 Reputation points Microsoft Vendor
    2024-12-27T02:19:31.2933333+00:00

    Hello, @@Glenn Maxwell,

    Welcome to the Microsoft Q&A platform!

    Your syntax for both tasks look mostly correct, I just provide some test results and official documents to help you finish your goals more efficient.

    1.Exporting Inactive Mailboxes to CSV

    After running the command you provided above, as the screenshots shown, all the inactive mailboxes with the fields DisplayName, PrimarySMTPAddress, and WhenSoftDeleted are exported to a CSV file.

    User's image

    2.Removing Email Addresses from the Retention Policy

    For removing email addresses from the retention policy using a CSV file, your syntax is also correct, which can be concluded from the official document.

    User's image

    If you want to learn more about how to delete an inactive mailbox, please refer to https://learn.microsoft.com/en-us/purview/delete-an-inactive-mailbox#remove-an-inactive-mailbox-from-a-retention-policy.

    Moreover, as phemanth said, to make sure the CSV file can be found, please make your CSV file (C:\mailboxes.csv) has a header named users:

    users 
    user1@contoso.com 
    user2@contoso.com
    

    To end up, although your syntax both correct, please ensure that you have the necessary permissions to run these commands. Should you need more help on this, you can feel free to post back. 


    If the answer is helpful, please click on ACCEPT ANSWER as it could help other members of the Microsoft Q&A community who have similar questions and are looking for solutions.

    Thank you for your support and understanding.

    Best Wishes,

    Alex Zhang

    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.