Avatar of Sid_F
Sid_F
 asked on

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
ExchangeWindows Server 2003

Avatar of undefined
Last Comment
Mohammed Khawaja

8/22/2022 - Mon
Will Szymkowski

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


Will.
Mohammed Khawaja

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 Szymkowski

@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.

Will.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
Sid_F

ASKER
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.
ASKER CERTIFIED SOLUTION
Mohammed Khawaja

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.