Deleting Disconnected mailboxes from Exchange 2007

By default deleted mailbox retention policy is 30 days and after that deleted mailboxes will be disconnected state for next 30 before its actually gets deleted off the store

Below powershell to get the list of all the users on the specific Exchange server who disconnected mailbox older than 10 days, you can modify the days based on your requirement into the variable $disconnectedUsers

 

$DisconnectedUsers = Get-MailboxStatistics -Server <servername> | where-object { $_.DisconnectDate -ne $null } | ?{$_.DisconnectDate -lt (get-date).AddDays(-10)} | Select DisplayName,Database,MailboxGuid

 

Below command will get the users from variable $DisconnectedUsers one by one in the for loop and delete the same

$DisconnectedUsers | ForEach { Remove-Mailbox -Database $_.Database -StoreMailboxIdentity $_.MailboxGuid -confirm:$false }

Leave a comment