Friday, August 21, 2009

Search Users by MailBox Limit attribute

'On error resume next
'set RootDSE = GetObject("LDAP://RootDSE")

set objFSO = CreateObject("Scripting.FileSystemObject")
'set objInputFile = objFSO.openTextFile("C:\Documents and Settings\Desktop\scripts\in.txt",1)
set objOutputFile = objFSO.CreateTextFile("C:\Documents and Settings\Desktop\scripts\TEXT.TXT",True)


Set con = CreateObject("ADODB.Connection")
Set com = CreateObject("ADODB.Command")


con.provider = "ADsDSOObject"
con.open "Active Directory Provider"
com.ActiveConnection = con
com.Properties("searchscope") = 2
com.Properties("Page Size") = 100000


strSQL="select distinguishedName,cn,displayName,mail from 'LDAP://dc=ABC,dc=com'where objectclass='user'and objectclass <>'computer'"
com.CommandText = strSQL
Set rs = com.Execute
While Not rs.EOF
Set objUser = GetObject("LDAP://" & rs("distinguishedName"))

if mDBUseDefaults <> "FALSE" and mDBStorageQuota = "" and mDBOverQuotaLimit = "" then

objOutputFile.writeLine rs("cn") & "|" & rs("displayName") & "|" & rs("mail")

'rs.MoveNext
end if
rs.movenext
Wend

'Wend
msgbox "done"
set RootDSE = Nothing
set con = Nothing
set objUser = Nothing

No comments: