List Exchange 5.5 mailboxes and distributionlists.

'*****************************************************************
'** Script: ListExchange.vbs
'** Version: 1.0
'** Created: 01-04-2003 9:36
'** Author: Adriaan Westra
'** E-mail: 
'** Purpose / Comments:
'** List mailboxes and distribution lists from exchange 5.5
'**
'**
'** Changelog :
'** 01-04-2003 9:37 : Initial version
'**
'*****************************************************************

Dim Version : Version = "1.0" ' Script version
Dim Author : Author = "Adriaan Westra"
Dim Email : Email = ""
'*****************************************************************
'** Add Error Handling
on error resume Next

'*****************************************************************
'** Make sure the script is started with cscript
If InStr(wscript.FullName, "wscript.exe") > 0 Then
MsgBox "Please run this script with cscript.exe." & Chr(13) & _
"For example : cscript " & WScript.ScriptName & " /?", _ 
vbExclamation, WScript.ScriptName
WScript.Quit(1)
End If

'*****************************************************************
'** Get startup path from scriptfullname
Pos = InStr(wscript.ScriptFullName, wscript.ScriptName)
strPath = Mid(wscript.ScriptFullName,1,Pos - 1)

'*****************************************************************
'** Get commandline parameters
Set Args = Wscript.Arguments

'*****************************************************************
'** Check for help in commandline parameters
If Args.Count = 1 Then
   If InStr(Args(0),"/?") > 0 Or InStr(UCase(Args(0)),"/H") > 0 _ 
   Or InStr(UCase(Args(0)),"/HELP") > 0 Then
      DisplayHelp
      Wscript.quit(0)
   End if
End If


'*****************************************************************
'** Declare Variables
'** name of the exchange server
Dim strExchangeServer : strExchangeServer = "Server" 
'** Name of the site
Dim strSite : strSite = "Site" 
'** Name of the organization
Dim strOrganization : strOrganization = "Organization" 

Set objRec = GetObject("LDAP://" & strExchangeServer & _
  "/cn=Recipients,ou=" & strSite & ",o="& strOrganization )

WScript.echo "Display maiboxes from organization " & _ 
  strOrganization & " Site " & strSite & _ 
  " Server " & strExchangeServer

For each objRecipient in objRec
   RC = objRecipient.Get("MAPI-Recipient") 
   If err.number = 0 Then
      WScript.Echo objRecipient.cn
      WScript.Echo objRecipient.rdn
   Else
      err.clear
   End If
next


WScript.echo "Display distribution lists from organization " & _
   strOrganization & " Site " & _
   strSite & " Server " & strExchangeServer

For each objRecipient in objRec
    RC = objRecipient.Get("Member") 
    If err.number = 0 Then
       WScript.Echo objRecipient.cn
    Else
       err.clear
    End If
next

'*****************************************************************
'** End script
Wscript.Quit()

'*****************************************************************
'** Sub: DisplayHelp
'** Version: 1.0
'** Created: 24-03-2003 8:22
'** Author: Adriaan Westra
'** E-mail: 
'**
'** Purpose / Comments:
'** Display help for script
'**
'** Arguments :
'**
'** Wijzigingslog :
'** 24-03-2003 8:22 : InitiŽle versie
'**
'*****************************************************************
Sub DisplayHelp()
   strComment = string(2,"*")
   strCmntLine = String(79, "*") 
   wscript.echo strCmntline
   wscript.echo strComment
   wscript.echo strComment & " Online help for " & _ 
      Wscript.scriptname & " version : " & Version
   wscript.echo strComment
   wscript.echo strComment & " Usage : cscript " & _ 
      Wscript.scriptname 
   wscript.echo strComment
   wscript.echo strComment & " Purpose : List mailboxes and " & _
    " distribution lists from exchange 5.5"
   wscript.echo strComment
   wscript.echo strComment & " Author : " & Author
   wscript.echo strComment & " E-mail : " & Email
   wscript.echo strComment
   wscript.echo strCmntline
End Sub