Script to populate/generate MAILBOXES.TXT

Hello

Does anyone have a VBS script which will automatically populate the MAILBOXES.TXT file which is used by exmerge?

I need to run a scheduled task which imports a permission into every users mailbox using exmerge.

I have found a script which generates each users pst file, by copying a template pst file I have created (which includes the relevant permission change)

I can also script the Exmerge command, but need the mailboxes.txt file to automatically update with all the entire mailbox list.

The sort of thing I want it to generate is this:
/O=DOMAIN/OU=FIRST ADMINISTRATIVE GROUP/CN=RECIPIENTS/CN=JOE.BLOGGS

for each user.

Any ideas?

Thanks

Rich
LVL 2
ScintillateRichAsked:
Who is Participating?
 
LeeDerbyshireConnect With a Mentor Commented:
Try this.  You'll need to change any yourdomain and any com bits:

  Set objConn = CreateObject("ADODB.Connection")
  objConn.Provider = "ADsDSOObject"
  objConn.Properties("ADSI Flag") = 33 ' 1
  objConn.Open "ADs Provider"
  Set objCmd = CreateObject("ADODB.Command")
  objCmd.ActiveConnection = objConn
  strSQL = "<LDAP://CN=Default Global Address List,CN=All Global Address Lists,CN=Address Lists Container,CN=yourdomain,CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=yourdomain,DC=com>;;purportedSearch"
  objCmd.CommandText = strSQL
  Set objRs = objCmd.Execute
  strSearch = objRs("purportedSearch")
  strSQL = "<GC://DC=yourdomain,DC=com>;(&"
  strSQL = strSQL & strSearch & "(!(msExchHideFromAddressLists=TRUE)))"
  strSQL = strSQL & ";legacyExchangeDN"
  objCmd.CommandText = strSQL
  objCmd.Properties("Sort on") = "displayName"
  Set objRs = objCmd.Execute
  Set fso = CreateObject("Scripting.FileSystemObject")
  Set f = fso.OpenTextFile("C:\test.txt", 2, True)
  Do While Not(objRs.EOF)
    f.WriteLine objRs("legacyExchangeDN")
    objRs.MoveNext
  Loop
  f.Close
  Set f = Nothing : Set fso = Nothing
  Set objConn = Nothing : Set objCmd = Nothing : Set objRs = Nothing
0
 
LeeDerbyshireCommented:
Um, hang on.  Which version of Exchange?  I assumed 2003 here.
0
 
ScintillateRichAuthor Commented:
Thank you so much for your help!

Is there anyway I can stop the script outputing security and distribution groups?

Thanks

Rich
0
 
LeeDerbyshireCommented:
Well, it's based around the GAL purportedSearch, so you could ignore that, and build your own query.  Instead of

  strSearch = objRs("purportedSearch")

you could try

  strSearch = (&(objectCategory=person)(objectClass=user)(mailnickname=*))

It's very hard to predict what you'll get with these things.  Let me know what this one returns.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.