Query 2007 exchange for disabled AD users

I want to identify what exchange mailboxes are associated with users who are disabled in AD or no longer exist in AD. The environment is 2003 domain with 2007 exchange. thanks
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Will SzymkowskiSenior Solution ArchitectCommented:
From the Exchange Management Shell run the following command...
Import-module activedirectory
Get-ADUser -filter {Enable -eq $false} -properties Enabled, sAMAccountName, Name, msExchWhenMailboxCreated | ? {$_.msExchWhenMailboxCreated -notlike $null} | select Name, sAMAccountName, Name, Enabled | export-csv "c:\disabledusers.csv" -NoTypeInformation

Open in new window

Mohammed KhawajaManager - Infrastructure:  Information TechnologyCommented:
You could also run the command listed below to list you disabled accounts in Active Directory

dsquery user -disabled -limit 0 > disabled-users.txt

I believe the script provided by Will will not work if you do not have AD Web Services which is available if you have Win2K8 or higher DCs.
Will SzymkowskiSenior Solution ArchitectCommented:
@Mohammed - you might be correct but I have not tested this scenario within the Exchange Management Shell. However the command you have provided will get all AD users regardless if the user has a mailbox or not. The original question is regarding mailboxes where the AD Account is disabled.

Sid_FAuthor Commented:
I have tried to run the import-module activedirectory but receive the error  it was not loaded because a valid a valid module file was not found in any module directory. Just to confirm I am running this command on exchange powershell thanks.
Mohammed KhawajaManager - Infrastructure:  Information TechnologyCommented:
It seems like you have Windows Server 2003 DCs and the PowerShell requires AD Web Services.  You could either install the AD Web Services or you could do one of the following:

1.  Use dsquery to find disabled accounts and then correlate them to Exchange mailboxes (Excel vlookup)
2.  Download PowerGui and obtain AD and Exchange plugins.  Use that to obtain what you need

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.