I
would just say that iteration through the users in this way has two
failings
1. If
you have users in some other container or OU, you ain't seeing them
here.
2.
Iteration is kind of slow compared to doing an LDAP search and displaying the
specific fields you asked to have returned, even if you use vbscript and ado.
Basically as your directory grew this script would really slow down.
If I understand what you are trying to get here (white space
management is throwing me), to display the user's that have mailboxes
userprincipalname, samaccountname, homemdb and proxyaddresses info I think I
would simply do something like:
adfind
-default -f "&(objectcategory=person)(samnaccountname=*)(homemdb=*)"
userprincipalname samaccountname homemdb proxyadddresses
I
don't have the exchange attributes handy to see if homemdb is indexed, if it
isn't I would use some other exchange attribute that is indexed instead. The
beauty of that query is that it will do the entire domain, if you just wanted
the users container you could do
adfind
-b cn=users,dc=domain,dc=com -f
"&(objectcategory=person)(samnaccountname=*)(homemdb=*)" userprincipalname
samaccountname homemdb proxyadddresses
or if
you wanted the whole forest you could do
adfind
-gc -b "" -f
"&(objectcategory=person)(samnaccountname=*)(homemdb=*)" userprincipalname
samaccountname homemdb proxyadddresses
It
will have a count of how many matching objects at the very end of the
run.
Sorry I didn't post script code, shouldn't be hard to put it
together though if you understand the concepts I am trying to propose. Should be
a ton of stuff you can leverage at the script center or in
microsoft.public.adsi.general that you can convert.
joe
--
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Michael B. Smith
Sent: Wednesday, June 11, 2003 5:12 PM
To: [EMAIL PROTECTED]
Subject: RE: [ActiveDir] Looking up all email addressesThanks. I just figured it out a couple of minutes ago. This works:Set objContainer = GetObject("LDAP://" + DomainName)objContainer.Filter = Array("User")
i = 0For Each objUser In objContainer
name = objUser.name
wscript.echo "name: " & name & " upn: " & objUser.UserPrincipalName & " sam: " & objUser.samAccountName
name = Right(name, Len(name) - 3)
Set objMailbox = objUser
If objMailbox.HomeMDB = "" Then
'Wscript.echo name + " (no mailbox)"
Else
'Wscript.echo name + " (has mailbox)"
'Wscript.echo objMailbox.HomeMDB
' email addresses
Set objR = objUser
AddressList = objR.ProxyAddresses
for each Address in AddressList
if lcase (left (Address, 5)) = "smtp:" Then
Wscript.echo Address
end if
next
End If
i = i + 1
Next'Wscript.echo "Number of users found in " & DomainName & ": " & i-----Original Message-----
From: Roger Seielstad [mailto:[EMAIL PROTECTED]
Sent: Wednesday, June 11, 2003 5:03 PM
To: '[EMAIL PROTECTED]'
Subject: RE: [ActiveDir] Looking up all email addressesI wrote the code below a while ago to do something similar, and should work for you.Its written for an Exchange 5.5 server, but the logic is pretty similar for AD/E2k as well.--------------------------------------------------------------
Roger D. Seielstad - MTS MCSE MS-MVP
Sr. Systems Administrator
Inovis Inc.-----Original Message-----
From: Michael B. Smith [mailto:[EMAIL PROTECTED]
Sent: Wednesday, June 11, 2003 3:51 PM
To: [EMAIL PROTECTED]
Subject: [ActiveDir] Looking up all email addressesI need a piece of code that, given a user object, returns me an object or collection to all of the email addresses for that user. I can't find the object.Help!Set objContainer = GetObject("LDAP://CN=Users," + DomainName)objContainer.Filter = Array("User")
i = 0For Each objUser In objContainer
name = objUser.name
name = Right(name, Len(name) - 3)
Set objMailbox = objUser
<<---->>> code goes here!!!If objMailbox.HomeMDB = "" Then
Wscript.echo name + " (no mailbox)"
Else
Wscript.echo name + " (has mailbox)"
End If
i = i + 1
Next
Wscript.echo "Number of users found in the DS (in the default container): " & iThanks
