Link to home
Start Free TrialLog in
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
Avatar of Will Szymkowski
Will Szymkowski
Flag of Canada image

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.
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.
@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.
Avatar of Sid_F
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
Avatar of Mohammed Khawaja
Mohammed Khawaja
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial