inactive mailboxes

Glenn Maxwell 12,876 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 Microsoft email and calendaring hosted service.
6,188 questions
Exchange | Hybrid management
Windows for business | Windows Server | User experience | PowerShell
Microsoft Security | Microsoft Purview
{count} votes

Accepted answer
  1. 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


1 additional answer

Sort by: Most helpful
  1. phemanth 15,765 Reputation points Microsoft External Staff Moderator
    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

    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.