Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.
July 18, 2007
A. The following script generates a list of all the SMTP addresses for enabled users. (You need to modify the strRootDomain variable.)
'Option ExplicitDim objCommand, objConnection, objChild, objUserConnection, strBase, strFilter, strAttributes,strsn, strgivenname,strinitialsDim objShell, lngBiasKey, k, PasswordExpiry, strRootDomain, emailDim strQuery, objRecordset, strName, strCN' ********************* CHANGE THESE VALUES TO ROOT OF WHERE USERS WILLBE SEARCHED ***********************************strRootDomain="ou=users,dc=savilltech,dc=net"'*****************************************************************************************************************************************Set objCommand = CreateObject("ADODB.Command")Set objConnection = CreateObject("ADODB.Connection")objConnection.Provider = "ADsDSOObject"objConnection.Open "Active Directory Provider"objCommand.ActiveConnection = objConnectionstrBase = ""strFilter ="(&(objectCategory=person)(objectClass=user)(proxyaddresses=*)(!(useraccountcontrol:1.2.840.113556.1.4.803:=2)))"strAttributes = "sAMAccountName,cn,distinguishedName,displayname"strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"objCommand.CommandText = strQueryobjCommand.Properties("Page Size") = 100objCommand.Properties("Timeout") = 30objCommand.Properties("Cache Results") = FalseSet objRecordSet = objCommand.ExecuteWScript.echo "Running at " & Date()Do Until objRecordSet.EOF strName = objRecordSet.Fields("sAMAccountName").Value Wscript.Echo "Display Name: " & objRecordSet.Fields("displayname").Value Set objUserConnection = GetObject("LDAP://" &objRecordSet.Fields
("distinguishedName").Value) For each email in objUserConnection.proxyAddresses If Left (email,5) = "SMTP:" Then WScript.Echo "Primary e-mail address: " & Mid (email,6) ElseIf Left (email,5) = "smtp:" Then WScript.Echo "Seconary e-mail address: " & Mid (email,6) End If Next objRecordSet.MoveNextLoopobjConnection.Close
You can change the output format as necessary. Run Cscript listsmtp.vbs.
You May Also Like