Search for User Accounts That Have Been Disabled

Demonstration script that returns the names of all disabled user accounts in Active Directory. Uses the LDAP search syntax.

VBScript Code

On Error Resume Next

Set objConnection = CreateObject("ADODB.Connection")
Set objCommand =   CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection

objCommand.Properties("Page Size") = 1000

objCommand.CommandText = _
    ";(&(objectCategory=User)" & _
Set objRecordSet = objCommand.Execute

Do Until objRecordSet.EOF
    Wscript.Echo objRecordSet.Fields("Name").Value