VBScript to Retrieve All proxyAddresses from AD not working???
So here is my script and for some reason the IsObject(oUser.proxyAddresses) is always returnFALSE??? Please help? My goal here is to export a list of all user email addresses from AD. Dim rootDSE, domainObjectSet rootDSE=GetObject("LDAP://RootDSE")DomainContainer = rootDSE.Get("defaultNamingContext") Set fs = CreateObject ("Scripting.FileSystemObject")Set userFile = fs.CreateTextFile ("c:\users.csv") Set conn = CreateObject("ADODB.Connection")conn.Provider = "ADSDSOObject"conn.Open "ADs Provider" ldapStr = "<LDAP://" & DomainContainer & ">;(& (mailnickname=*) (| (&(objectCategory=person)(objectClass=user)(!(homeMDB=*))(!(msExchHomeServerName=*)))(&(objectCategory=person)(objectClass=user)(|(homeMDB=*)(msExchHomeServerName=*))) ));adspath;subtree" Set rs = conn.Execute(ldapStr) While Not rs.EOF Set oUser = GetObject (rs.Fields(0).Value)userFile.Write oUser.displayName & "," & oUser.sAMAccountName & "," If IsObject(oUser.proxyAddresses) = True Then for each email in oUser.proxyAddresses userFile.Write oUser.proxyAddresses & "," next End If userFile.WriteLine "" rs.MoveNextWend
September 15th, 2006 5:01am

Hi Derek, oUser.proxyAddresses is of type Variant(), not an Object. Try removing the IsObject check and replace with.... Dim rootDSE, domainObject, proxyAddresses, proxyAddressSet rootDSE=GetObject("LDAP://RootDSE")DomainContainer = rootDSE.Get("defaultNamingContext") Set fs = CreateObject ("Scripting.FileSystemObject")Set userFile = fs.CreateTextFile ("C:\users.csv") Set conn = CreateObject("ADODB.Connection")conn.Provider = "ADSDSOObject"conn.Open "ADs Provider" ldapStr = "<LDAP://" & DomainContainer & ">;(&(mailnickname=*)(|(&(objectCategory=person)(objectClass=user)(!(homeMDB=*))(!(msExchHomeServerName=*)))(&(objectCategory=person)(objectClass=user)(|(homeMDB=*)(msExchHomeServerName=*)))));adspath;subtree;" Set rs = conn.Execute(ldapStr) While Not rs.EOF Set oUser = GetObject (rs.Fields(0).Value) userFile.Write oUser.displayName & "," & oUser.sAMAccountName & "," proxyAddresses = oUser.proxyAddressesfor each proxyAddress in proxyAddressesuserFile.Write proxyAddress & ","next userFile.WriteLine ""rs.MoveNextWend Hope this helps. Rob Costello
Free Windows Admin Tool Kit Click here and download it now
September 15th, 2006 2:27pm

Your right that fixed the runtime error, but I am not getting aback any email addresess now? sample line below C1snwgqgaa EXVS02,C1snwgqgaa, [email addresses would be here] please help
September 15th, 2006 9:54pm

Hi Derek,Sorry, in my last post I forgot one thing. In your ADO command your only returning adspath. You'll need to update it to include proxyAddresses. Try this...ldapStr = "<LDAP://" & DomainContainer & ">;(&(mailnickname=*)(|(&(objectCategory=person)(objectClass=user)(!(homeMDB=*))(!(msExchHomeServerName=*)))(&(objectCategory=person)(objectClass=user)(|(homeMDB=*)(msExchHomeServerName=*)))));adspath,proxyAddresses;subtree;"See how that goes.RC
Free Windows Admin Tool Kit Click here and download it now
September 16th, 2006 3:12am

thank you...but now I get "object is not a collection" (assuming this is referring to the proxAddressses). Here is the current code I am running that produces this error... Dim rootDSE, domainObject, proxyAddresses, proxyAddressSet rootDSE=GetObject("LDAP://RootDSE")DomainContainer = rootDSE.Get("defaultNamingContext") Set fs = CreateObject ("Scripting.FileSystemObject")Set userFile = fs.CreateTextFile ("C:\users.csv") Set conn = CreateObject("ADODB.Connection")conn.Provider = "ADSDSOObject"conn.Open "ADs Provider" ldapStr = "<LDAP://" & DomainContainer & ">;(&(mailnickname=*)(|(&(objectCategory=person)(objectClass=user)(!(homeMDB=*))(!(msExchHomeServerName=*)))(&(objectCategory=person)(objectClass=user)(|(homeMDB=*)(msExchHomeServerName=*)))));adspath,proxyAddresses;subtree;" Set rs = conn.Execute(ldapStr) While Not rs.EOF Set oUser = GetObject (rs.Fields(0).Value) userFile.Write oUser.displayName & "," & oUser.sAMAccountName & "," proxyAddresses = oUser.proxyAddresses for each proxyAddress in proxyAddresses userFile.Write proxyAddress & "," next userFile.WriteLine ""rs.MoveNextWend
September 16th, 2006 5:01pm

Hi Derek,What line is it erroring on? The code you have works for me on both Exch 2003 and Exch 2007 machines.You could also try to enumerate through the values returned from the ADO call instead of making a call to the directory with the ADSPath return value.Try...proxyAddresses = rs.Fields(1).Value for each proxyAddress in proxyAddresses userFile.Write proxyAddress & "," nextRob
Free Windows Admin Tool Kit Click here and download it now
September 17th, 2006 9:24am

Hi Rob, I thought you had made a post earlier over the weekend saying the script works on all of my Exchange servers...do you know of a solution that can be ran from a traditional member server node? I have little knowledge of AD/Exchange...but I do know there is a System.DirectoryServices namespace in the .Net Framework. Could these classes be used on a remote machine? Is there any other API for such a task? My Goal here is really quite simple "return all user email accounts, domains, and aliases from AD, from a remote server/machine". The results of this code would be used to construct Postini commands. Any help/light you could shed would be much appreciated. Thanks, Derek
September 18th, 2006 6:35pm

Hi Derek, I didn't realise you wanted to do this from a remote machine, but it shouldn't really matter, I can run your script from member servers and from client machines and it works as expected. As long as the machine is a member of the domain you are querying and it is run under the context of a user with appropriate permissions, it should still work. The System.DirectoryServices namespace can be used for this task too. You could also look at tools like DSGet.exe and DSQuery.exe, or PowerShell for this task, but I'd suspect you'll have the same issue. Update: Check out this blog by Kris Waters on extracting email addresses too... http://krisdev.blogspot.com/2006/03/for-all-users-that-have-exchange.html Sorry I couldn't be more helpful. Rob.
Free Windows Admin Tool Kit Click here and download it now
September 25th, 2006 4:34am

This worked for me.
July 6th, 2007 1:30am

Rob, If you get this, would you please explain why it only dumps 1000 records, and if you have a suggestion on how to fix that. -Boomer
Free Windows Admin Tool Kit Click here and download it now
July 6th, 2007 1:52am

Hi, ADO returns by default only 1000 records from AD. You can work around it by setting page size and and size limit on the adodb.command object. Const SizeLimit=10000 Command.Properties("Page Size") = 1000Command.Properties("Size Limit") = cint(SizeLimit) Hope this helps thor
August 22nd, 2007 11:17pm

I was just trying to use a very similar script and received the same error message as Derek ("object is not a collection"). It turned out that one of my user objects did not have any addresses so the proxyAddresses array did not exist. I changed the script slightly to ignore this problem and the script completed. on error resume next for each proxyAddress in proxyAddresses userFile.Write proxyAddress & "," next Hope this helps the next person with a less than pristine AD implementation!
Free Windows Admin Tool Kit Click here and download it now
September 20th, 2007 10:47pm

Just to add to Thor's comments. Page size should be set to less then 1000 to work around this constraint. I utilize 999. Also just set the size limit to 0 - this will allow for an unlimited number of results. command.properties("Page Size") = 999 command.properties("Size Limit") = 0 It seems that the base of this script is to pull proxyAddresses from AD. With that said you could use a very simple filter such as: (&(objectCategory=user)(objectClass=user)(proxyAddresses=*)) This will only bring back users that contain proxyAddresses in their user account.
March 11th, 2008 5:32pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics