Option Explicit
Dim strBase, strComputerName, strAttrs, strScope
Dim theServer, theSG, theConn, sg, mailDB, strUserName
Dim objRS, strMailBox, i, strUser, u, strDN
Dim person, arrAttendees, objTrans
Dim strSubject, strOrg, strBody
Const CdoDefaultFolderCalendar = 0
Const ADS_NAME_TYPE_1779 = 1
Const ADS_NAME_TYPE_CANONICAL = 2
Const ADS_NAME_TYPE_NT4 = 3
Const ADS_NAME_INITTYPE_GC = 3
Const ADS_NAME_TYPE_DISPLAY = 4
Const ADS_NAME_TYPE_DOMAIN_SIMPLE = 5
Const ADS_NAME_TYPE_ENTERPRISE_SIMPLE = 6
Const ADS_NAME_TYPE_GUID = 7
Const ADS_NAME_TYPE_UNKNOWN = 8
Const ADS_NAME_TYPE_USER_PRINCIPAL_NAME = 9
Const ADS_NAME_TYPE_CANONICAL_EX = 10
Const ADS_NAME_TYPE_SERVICE_PRINCIPAL_NAME = 11
Const ADS_NAME_TYPE_SID_OR_SID_HISTORY_NAME = 12
'On Error Resume Next
'------ CONFIG ------
strBase = "<LDAP://DC.Domain.com>;"
strComputerName = "Exchange.Domain.com"
strAttrs = "cn,sAMAccountName;"
strScope = "subtree"
u = 0
'------ END CONFIG ----
Set theServer = CreateObject("CDOEXM.ExchangeServer")
Set theSG = CreateObject("CDOEXM.StorageGroup")
Set theConn = CreateObject("ADODB.Connection")
theConn.Open "Provider=ADsDSOObject;"
theServer.DataSource.Open strComputerName
' look at all storage groups for mailboxes
' strComputerName is Exchange Server
' strMailBox is username
' strUser is cn
For Each sg In theServer.StorageGroups
WScript.Echo "Storage group " & Chr(34) & sg & Chr(34)
theSG.DataSource.open sg
i = 0
For Each mailDB In theSG.MailboxStoreDBs
i = i+1
WScript.Echo " Mailbox database " & i & ": " & mailDB & vbcrlf
'wscript.Echo " Users: "
Set objRS = theConn.Execute(strBase & "(&(homeMDB=" & mailDB & ")(sAMAccountName=*)(!mail=*system*));" & strAttrs & strScope)
objRS.MoveFirst
While Not objRS.EOF And ObjRS.RecordCount > 0
u = u + 1
strUser = objRS.Fields(0).Value
strMailBox = objRS.Fields(1).Value
CALL GetApptData(strComputerName,strMailBox,strUser)
strMailBox = ""
objRS.MoveNext
Wend
'wscript.echo Chr(13) & Chr(13)
Next
Next
Function GetApptData(strComputerName,strMailBox,strUser)
Dim objSession, strProfileInfo, objAppointment, strAttendees, Attendee
Dim objAppointmentItems, objFolder
strProfileInfo = strComputerName & vbLf & strMailBox
Set objSession = CreateObject("MAPI.Session")
objSession.Logon "", "", False, True, 0, True, strProfileInfo
strMailBox = ""
Set objFolder = objSession.GetDefaultFolder(CdoDefaultFolderCalendar)
' Get all Appointment Items
Set objAppointmentItems = objFolder.Messages
' Loop through the AppointmentItems collection
For Each objAppointment In objAppointmentItems
For Each Attendee In objAppointment.Recipients
strAttendees = strAttendees & " ; " & Attendee
Next
' Display data for each appointment
If objAppointment.IsRecurring = True And strAttendees <> "" Then
wscript.echo "############NEW USER###################################" & vbcrlf
wscript.echo strUser & ";" & objAppointment.Subject & ";" & objAppointment.StartTime & ";" & objAppointment.EndTime & ";" & objAppointment.Organizer & strAttendees
wscript.echo "AFTER OUTPUT>>>>>>>>>>>>>>>>>> " & strAttendees
arrAttendees = Split(strAttendees," ; ")
For Each person In arrAttendees
wscript.echo "PERSON: " & person
wscript.echo "AFTER PERSON>>>>>"
Set objTrans = CreateObject("NameTranslate")
objTrans.Init ADS_NAME_INITTYPE_GC, ""
objTrans.Set ADS_NAME_TYPE_DISPLAY, person
strUserName = objTrans.Get(ADS_NAME_TYPE_NT4)
'wscript.echo "###############################################" & vbcrlf
strSubject = objAppointment.Subject
strOrg = objAppointment.Organizer
strBody = objAppointment.Body
CALL GetApptData2(CdoDefaultFolderCalendar,strComputerName,strUserName,person,strSubject,strOrg,strBody)
Next
End If
strAttendees = ""
Next
'Clean Up
objSession.Logoff
Set objSession = Nothing
End Function
Function GetApptData2(CdoDefaultFolderCalendar,strComputerName,strUserName,person,strSubject,strOrg,strBody)
Dim objSession2, strProfileInfo2, objAppointment2, strAttendees2, Attendee2
Dim objAppointmentItems2, objFolder2
strProfileInfo2 = strComputerName & vbLf & strUserName
wscript.echo "11111111111111"
Set objSession2 = CreateObject("MAPI.Session")
objSession2.Logon "", "", False, True, 0, True, strProfileInfo2
strUserName = ""
Set objFolder2 = objSession2.GetDefaultFolder(CdoDefaultFolderCalendar)
wscript.echo "2222222222222222222"
' Get all Appointment Items
Set objAppointmentItems2 = objFolder2.Messages
' Loop through the AppointmentItems collection
For Each objAppointment2 In objAppointmentItems2
wscript.echo "33333333333333333333333"
For Each Attendee2 In objAppointment2.Recipients
strAttendees2 = strAttendees2 & " ; " & Attendee2
wscript.echo "4444444444444444444444444444"
Next
' Display data for each appointment
If strSubject = objAppointment2.Subject And strOrg = objAppointment2.Organizer And strBody = objAppointment2.Body Then
wscript.echo "555555555555555555555555555555"
wscript.echo vbtab & "Attendee Data: " & person2 & ";" & objAppointment2.Subject & ";" & objAppointment2.StartTime & ";" & objAppointment2.EndTime & ";" & objAppointment2.Organizer & strAttendees2
wscript.echo "666666666666666666666666666666666666"
End If
strAttendees2 = ""
Next
'Clean Up
objSession2.Logoff
Set objSession2 = Nothing
End Function
wscript.echo "Total User Count: " & u