VBScript for checking an Active Directory disabled users are hide in Global Address list or not.
Option Explicit
Dim objRootDSE,strDNSDomain,adoConnection,strQuery,adoRecordset,Field
'Check if Active Directory disabled users are hiden or not in Global Address list
wscript.echo "Searching all disabled users to check if they are hide in GAL or not please wait...."
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("defaultNamingContext")
Set adoConnection = CreateObject("ADODB.Connection")
adoConnection.Provider = "ADSDSOObject"
adoConnection.Open "ADs Provider"
strQuery = "<LDAP://" & strDNSDomain & ">;(&(objectCategory=person)(objectClass=user));adspath;subtree"
Set adoRecordset = adoConnection.Execute(strQuery)
' Loop through them...
Do While Not adoRecordset.EOF
Set Field = GetObject(adoRecordset.Fields(0).Value)
If IsArray(Field.proxyAddresses) and Field.accountDisabled = TRUE and Field.msExchHideFromAddressLists <> TRUE Then
wscript.echo "Account " & Field.displayname & " is disabled but not hide in Global Address list"
End If
adoRecordset.MoveNext
Loop
wscript.echo "Done"