Hi,
Knowing which forum to place this one in is a little tricky so looking at similar posts, I have chosen this one. Appologies if you don't agree...
Anyway, I have a script that pulls out all email addresses into a csv file, but it is only returning users up to 'R'. The script doesn't error and I can't see any reason for it in AD, Exchange or the script itself. Would anybody be able to shed any light on this?
Here is the script:
Many thanks in advance.
Woter
Knowing which forum to place this one in is a little tricky so looking at similar posts, I have chosen this one. Appologies if you don't agree...
Anyway, I have a script that pulls out all email addresses into a csv file, but it is only returning users up to 'R'. The script doesn't error and I can't see any reason for it in AD, Exchange or the script itself. Would anybody be able to shed any light on this?
Here is the script:
Code:
Set rootDSE=GetObject("LDAP://RootDSE")
DomainContainer = rootDSE.Get("defaultNamingContext")
csvFile = "C:\e-mails.csv"
Set fso = CreateObject ("Scripting.FileSystemObject")
If fso.FileExists(csvFile) Then
fso.DeleteFile(csvFile)
Set emFile = fso.CreateTextFile ("c:\e-mails.csv")
Else
Set emFile = fso.CreateTextFile ("c:\e-mails.csv")
End If
Set connDb = CreateObject("ADODB.Connection")
connDb.Provider = "ADSDSOObject"
connDb.Open "ADs Provider"
ldapStr = "<LDAP://" & DomainContainer & ">;(& (mailnickname=*) (| (&(objectCategory=person)(objectClass=user)(!(homeMDB=*))(!(msExchHomeServerName=*)))(&(objectCategory=person)(objectClass=user)(|(homeMDB=*)(msExchHomeServerName=*))) ));adspath;subtree"
Set rs = connDb.Execute(ldapStr)
While Not rs.EOF
Set oUser = GetObject (rs.Fields(0).Value)
emFile.Write oUser.displayName & ","
for each email in oUser.proxyAddresses
If InStr(email,"@myChosenDomain.co.uk") Then
emFile.Write email & ","
End If
Next
emFile.WriteLine ""
rs.MoveNext
Wend
Many thanks in advance.
Woter