If there’s one thing most IT department are not great at its removing Exchange Mailboxes for Disabled Users. So here’s a quick Powershell win to determine who within your Exchange organisation has a mailbox and a disabled AD account.
On-Premises Users
$Mailboxes = Get-Mailbox | where {$_.RecipientTypeDetails -eq 'UserMailbox'} $Disabled = @() Foreach ($Mailbox in $Mailboxes) { if((Get-ADUser -Identity $Mailbox.SamAccountName).Enabled -eq $False){ $Disabled += Get-MailboxStatistics $Mailbox.SamAccountName | Select -Property DisplayName,TotalItemSize } } $Disabled | Export-Csv -Path $env:userprofile\desktop\DisabledADUserwithMailbox.csv -NoTypeInformation
Cloud Users
Connect-MsolService $Mailboxes = Get-Mailbox | Where-Object {$_.RecipientTypeDetails -eq 'UserMailbox'} $Disabled = @() Foreach ($Mailbox in $Mailboxes) { if((Get-msolUser -userprincipalname $Mailbox.userprincipalname).Enabled -eq $False){ $Disabled += Get-MailboxStatistics $Mailbox.userprincipalname | Select-Object -Property DisplayName,TotalItemSize } } $Disabled | Export-Csv -Path $env:userprofile\desktop\DisabledAzureADUserwithMailbox.csv -NoTypeInformation
Regards
The Author – Blogabout.Cloud
Tweaked this a bit for unlimited results as well as reformatting the mailbox size to MB for easier sorting:
$Mailboxes = Get-Mailbox -resultsize unlimited| where {$_.RecipientTypeDetails -eq ‘UserMailbox’}
$Disabled = @()
Foreach ($Mailbox in $Mailboxes) {
if((Get-ADUser -Identity $Mailbox.SamAccountName).Enabled -eq $False){
$Disabled += Get-MailboxStatistics $Mailbox.SamAccountName | Select -Property DisplayName,@{expression={$_.totalitemsize.value.ToMB()};label=”Size(MB)”}
}
}
$Disabled | Export-Csv -Path $env:userprofile\desktop\DisabledADUserwithMailbox.csv -NoTypeInformation