Script to populate/generate MAILBOXES.TXT

Posted on 2006-05-11
Last Modified: 2012-08-14

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:

for each user.

Any ideas?


Question by:ScintillateRich
    LVL 31

    Accepted Solution

    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")
      Set f = Nothing : Set fso = Nothing
      Set objConn = Nothing : Set objCmd = Nothing : Set objRs = Nothing
    LVL 31

    Expert Comment

    Um, hang on.  Which version of Exchange?  I assumed 2003 here.
    LVL 2

    Author Comment

    Thank you so much for your help!

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


    LVL 31

    Expert Comment

    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.

    Featured Post

    Do email signature updates give you a headache?

    Constantly trying to correctly format email signatures? Spending all of your time at every user’s desk to make updates? Want high-quality HTML signatures on all devices, including on mobiles and Macs? Then, let Exclaimer solve all your email signature problems today!

    Join & Write a Comment

    Get an idea of what you should include in an email disclaimer with these Top 5 email disclaimer tips.
    ADCs have gained traction within the last decade, largely due to increased demand for legacy load balancing appliances to handle more advanced application delivery requirements and improve application performance.
    In this video we show how to create an Accepted Domain in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Mail Flow >> Ac…
    The basic steps you have just learned will be implemented in this video. The basic steps are shown to configure an Exchange DAG in a live working Exchange Server Environment and manage the same (Exchange Server 2010 Software is used in a Windows Ser…

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now