Share via

inactive mailboxes

Glenn Maxwell 13,761 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 
******@contoso.com 
******@contoso.com

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

Exchange Online
Exchange Online

A cloud-based service included in Microsoft 365, delivering scalable messaging and collaboration features with simplified management and automatic updates.

Exchange | Hybrid management
Exchange | Hybrid management

The administration of a hybrid deployment that connects on-premises Exchange Server with Exchange Online, enabling seamless integration and centralized control.

Windows for business | Windows Server | User experience | PowerShell
Microsoft Security | Microsoft Purview

Answer accepted by question author

Anonymous
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 
******@contoso.com 
******@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

Was this answer helpful?


1 additional answer

Sort by: Most helpful
  1. Anonymous
    2024-12-26T18:55:12.61+00:00

    @Glenn Maxwell

    Thanks for reaching out to Microsoft Q&A.

    Your PowerShell syntax looks mostly correct.

    Here are a few adjustments and confirm us:

    Exporting Inactive Mailboxes to CSV

    Your command to export inactive mailboxes is correct:

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

    Removing Email Addresses from the Retention Policy Your command to remove email addresses from the retention policy is also correct, but ensure your CSV file is formatted properly. Here’s the adjusted command:

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

    Make sure your CSV file (C:\mailboxes.csv) has a header named users:

    users
    ******@contoso.com
    ******@contoso.com
    

    I hope the above steps will resolve the issue, please do let us know if issue persists. Thank you

    Was this answer helpful?

    0 comments No comments

Your answer

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