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 namedusers
:
users
user1@contoso.com
user2@contoso.com
I hope the above steps will resolve the issue, please do let us know if issue persists. Thank you