Skip to main content

Combined Summary and Audit VBS Script for all appointments in all calendars on a Server via WebDAV

This is a combination of two of my posts from last week the first was Euricelia's "Creating a Report of Meeting Organizers for all appointments in all calendars on a Server via WebDAV" script and then my "Creating a Summary Email of all appointments within a Users Calendar for given period" . This script goes through every mailbox on the server using WebDAV via the Exchange Virtual directory and produces a HTML report of all the meeting of all users on the server during the configured time period with Outlook hyperlinks to all the appointments. I've added two extra columns to this report the first is the free/busy status of the appointment (useful if you have change the free busy status of appointment in resource mailboxes) and also the new Time Zone Mapi property that Matt Stehle blogged about the other day. (This is displayed in the report as NewClients) which should show whether the rebasing tool has modified the appointment (whether its now set to the correct time is another matter completely unless the Server develops ESP you can never be 100% sure)

To run this script you need to set the the following commandline variables

servername = "SERVERNAME"
username = "USERNAME"
password = "PASSWORD"

If you using NTLM authentication in OWA then you can leave the Username and Password blank (make sure you set them to null though). This script wont really work if you using FBA for this you should look at the virtual admin root or see the powershell sample in my next post.

I've put a downloadable copy of this script here the script itself looks like

on error resume next
servername = "SERVERNAME"
public username
public password
username = "USERNAME"
password = "PASSWORD"
public datefrom
public dateto
datefrom = "2007-03-11T00:00:00Z"
dateto = "2007-04-01T00:00:00Z"
trReportBody = ""

set shell = createobject("wscript.shell")
set conn1 = createobject("ADODB.Connection")


set conn = createobject("ADODB.Connection")
set com = createobject("ADODB.Command")
Set iAdRootDSE = GetObject("LDAP://RootDSE")
strNameingContext = iAdRootDSE.Get("configurationNamingContext")
strDefaultNamingContext = iAdRootDSE.Get("defaultNamingContext")
Conn.Provider = "ADsDSOObject"
Conn.Open "ADs Provider"
svcQuery = "<LDAP://" & strNameingContext &amp;amp;amp;amp; ">;(&(objectCategory=msExchExchangeServer)(cn="
& Servername & "));cn,name,legacyExchangeDN;subtree"
Com.ActiveConnection = Conn
Com.CommandText = svcQuery
Set Rs = Com.Execute
while not rs.eof
GALQueryFilter =
"(&(&(&(&(mailnickname=*)(!msExchHideFromAddressLists=TRUE)((&(objectCategory=person)(objectClass=user)(msExchHomeServerName="
&rs.fields("legacyExchangeDN") &amp;amp;amp;amp; ")) )))))"
strQuery = "<LDAP://" & strDefaultNamingContext &amp;amp;amp;amp; ">;" & GALQueryFilter &
";distinguishedName,mail,displayname,mailnickname;subtree"
com.Properties("Page Size") = 100
Com.CommandText = strQuery
Set Rs1 = Com.Execute
while not Rs1.eof
wscript.echo "User: " & rs1.fields("displayname")
user = rs1.fields("mail")
call QueryAttendees(servername,user)
rs1.movenext
wend
rs.movenext
wend
rs.close
set conn = nothing
set com = Nothing
rpReport = rpReport &amp;amp;amp;amp; "<table border=""1"" width=""100%"">" & vbcrlf
rpReport = rpReport & " <tr>" & vbcrlf
rpReport = rpReport & "<td align=""center"" bgcolor=""#000080""
width=""15%""><b><font color=""#FFFFFF"">Start Time</font></b></td>" & vbcrlf
rpReport = rpReport & "<td align=""center"" bgcolor=""#000080""
width=""15%""><b><font color=""#FFFFFF"">End time</font></b></td>" & vbcrlf
rpReport = rpReport & "<td align=""center"" bgcolor=""#000080""
width=""30%""><b><font color=""#FFFFFF"">Subject</font></b></td>" & vbcrlf
rpReport = rpReport & "<td align=""center"" bgcolor=""#000080""
width=""10%""><b><font color=""#FFFFFF"">Location</font></b></td>" & vbcrlf
rpReport = rpReport & "<td align=""center"" bgcolor=""#000080""
width=""10%""><b><font color=""#FFFFFF"">Organizer</font></b></td>" & vbcrlf
rpReport = rpReport & "<td align=""center"" bgcolor=""#000080""
width=""10%""><b><font color=""#FFFFFF"">Free/Busy</font></b></td>" & vbcrlf
rpReport = rpReport & "<td align=""center"" bgcolor=""#000080""
width=""10%""><b><font color=""#FFFFFF"">New Clients</font></b></td>" & vbcrlf
rpReport = rpReport & "</tr>" & vbcrlf
rpReport = rpReport & trReportBody
rpReport = rpReport & "</table>" & vbcrlf
Set fso = CreateObject("Scripting.FileSystemObject")

set wfile = fso.opentextfile("c:\temp\" & servername & ".htm",2,true)
wfile.write rpReport
wfile.close
set wfile = nothing
set fso = Nothing
wscript.echo "Done"


Public Sub QueryAttendees(server,mailbox)

On Error Resume Next

strURL = "http://" & server &amp; "/exchange/" & mailbox & "/calendar/"
strQuery = "<?xml version=""1.0""?><D:searchrequest xmlns:D = ""DAV:""
xmlns:b=""urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/"">"
strQuery = strQuery & "<D:sql>SELECT ""DAV:displayname"",
""urn:schemas:httpmail:subject"", "
strQuery = strQuery & """DAV:creationdate"", "
strQuery = strQuery & """http://schemas.microsoft.com/mapi/proptag/0x0FFF0102""
As EntryID, "
strQuery = strQuery & """urn:schemas:httpmail:fromname"",
""urn:schemas:calendar:dtstart"", ""urn:schemas:calendar:dtend"", "
strQuery = strQuery &
"""http://schemas.microsoft.com/mapi/id/{00062002-0000-0000-C000-000000000046}/0x8205""
As BusyStatus,"
strQuery = strQuery &
"""http://schemas.microsoft.com/mapi/id/{00062002-0000-0000-C000-000000000046}/0x825E""
As NewClients,"
strQuery = strQuery & " ""urn:schemas:calendar:location"",
""http://schemas.microsoft.com/mapi/apptstateflags"" FROM scope('shallow
traversal of """
strQuery = strQuery & strURL &amp;amp;amp;amp; """') Where ""DAV:ishidden"" = False AND
""DAV:contentclass"" = 'urn:content-classes:appointment' AND "
strQuery = strQuery & " NOT ""urn:schemas:calendar:instancetype"" = 1 AND "
strQuery = strQuery & """urn:schemas:calendar:dtstart"" &lt;= CAST(""" & dateto
& """ as 'dateTime') AND "
strQuery = strQuery &amp; """urn:schemas:calendar:dtend"" &gt;= CAST(""" & datefrom
& """ as 'dateTime')</D:sql></D:searchrequest>"


wscript.echo strQuery
set req = createobject("microsoft.xmlhttp")
req.open "SEARCH", strURL, false, username, password

If Err.Number <> 0 Then
WScript.Echo "Error Opening Search"
WScript.Echo Err.Number & ": " & Err.Description
End If

req.setrequestheader "Content-Type", "text/xml"
req.setRequestHeader "Translate","f"
req.setRequestHeader "Depth", "1,noroot"
req.send strQuery

If Err.Number <> 0 Then
WScript.Echo "Error Sending Query"
WScript.Echo Err.Number & ": " & Err.Description
End If

wscript.echo req.status
wscript.echo "response" & req.responseXML

If req.status >= 500 Then
wscript.echo "Status: " & req.status
wscript.echo "Status text: An error occurred on the server."
ElseIf req.status = 207 Then
set oResponseDoc = req.responseXML
set oDisplayNameNodes = oResponseDoc.getElementsByTagName("a:displayname")
set oHrefNodes = oResponseDoc.getElementsByTagName("a:href")
set oSubject = oResponseDoc.getElementsByTagName("d:subject")
set oEndTime = oResponseDoc.getElementsByTagName("e:dtend")
Set oStartTime = oResponseDoc.getElementsByTagName("e:dtstart")
Set oLocation = oResponseDoc.getElementsByTagName("e:location")
Set oAppstate = oResponseDoc.getElementsByTagName("f:apptstateflags")
Set oFromname = oResponseDoc.getElementsByTagName("d:fromname")
Set oEntryID = oResponseDoc.getElementsByTagName("EntryID")
Set oBusyStatus = oResponseDoc.getElementsByTagName("BusyStatus")
Set oNewClients = oResponseDoc.getElementsByTagName("NewClients")
For i = 0 To (oDisplayNameNodes.length -1)
set oNode = oDisplayNameNodes.nextNode
set oNode1 = oHrefNodes.nextNode
set oNode2 = oSubject.nextNode
set oNode3 = oEndTime.nextNode
Set oNode4 = oStarttime.nextNode
Set oNode5 = oLocation.nextNode
Set oNode6 = oAppstate.nextNode
Set oNode7 = oFromname.nextNode
Set oNode8 = oEntryID.nextNode
Set oNode9 = oBusyStatus.nextNode
Set oNode10 = oNewClients.nextNode
if oNode10.text = "" then
ncNewclients = "False"
else
ncNewclients = "True"
end if
wscript.echo Octenttohex(oNode8.nodeTypedValue)
soOrgnizer = ""
soOrgnizer = oNode7.text
sdStartDate =
dateadd("h",toffset,DateSerial(Mid(oNode4.text,1,4),Mid(oNode4.text,6,2),Mid(oNode4.text,9,2))
&amp;amp;amp;amp; " " & Mid(oNode4.text,12,8))
edEndDate =
dateadd("h",toffset,DateSerial(Mid(oNode3.text,1,4),Mid(oNode3.text,6,2),Mid(oNode3.text,9,2))
&amp;amp;amp;amp; " " & Mid(oNode3.text,12,8))
wscript.echo soOrgnizer
wscript.echo
trReportBody = trReportBody &amp;amp;amp;amp; "<tr>" & vbcrlf
trReportBody = trReportBody & "<td align=""center"" width=""15%"">" &
sdStartDate &amp;amp;amp;amp; " </td>" & vbcrlf
trReportBody = trReportBody & "<td align=""center"" width=""15%"">" & edEndDate
& "&nbsp;</td>" & vbcrlf
trReportBody = trReportBody & "<td align=""center"" width=""30%""><a
href=""outlook:" & Octenttohex(oNode8.nodeTypedValue) & """>" & oNode2.text &
"</a> </td>" & vbcrlf
trReportBody = trReportBody & "<td align=""center"" width=""10%"">" &
oNode5.text & "&nbsp;</td>" & vbcrlf
trReportBody = trReportBody & "<td align=""center"" width=""10%"">" & soOrgnizer
&amp;amp;amp;amp; " </td>" & vbcrlf
trReportBody = trReportBody & "<td align=""center"" width=""10%"">" &
GetBusyStatusText(oNode9.text) &amp;amp;amp;amp; " </td>" & vbcrlf
trReportBody = trReportBody & "<td align=""center"" width=""10%"">" &
ncNewclients &amp;amp;amp;amp; " </td>" & vbcrlf
trReportBody = trReportBody & "</tr>" & vbcrlf

Next
Else
wscript.echo "Status: " & req.status
wscript.echo "Status text: " & req.statustext
wscript.echo "Response text: " & req.responsetext
End If

End Sub

Function Octenttohex(OctenArry)
ReDim aOut(UBound(OctenArry))
For i = 1 to UBound(OctenArry) + 1
if len(hex(ascb(midb(OctenArry,i,1)))) = 1 then
aOut(i-1) = "0" & hex(ascb(midb(OctenArry,i,1)))
else
aOut(i-1) = hex(ascb(midb(OctenArry,i,1)))
end if
Next
Octenttohex = join(aOUt,"")
End Function

Function GetBusyStatusText(bsBusyStatusProp)

select case bsBusyStatusProp
case 0 GetBusyStatusText = "Free"
case 1 GetBusyStatusText = "Tentative"
case 2 GetBusyStatusText = "Busy"
case 3 GetBusyStatusText = "Out of Office"
Case Else GetBusyStatusText = "Unknown"
end Select

End Function

Popular posts from this blog

Export calendar Items to a CSV file using Microsoft Graph and Powershell

For the last couple of years the most constantly popular post by number of views on this blog has been  Export calendar Items to a CSV file using EWS and Powershell closely followed by the contact exports scripts. It goes to show this is just a perennial issue that exists around Mail servers, I think the first VBS script I wrote to do this type of thing was late 90's against Exchange 5.5 using cdo 1.2. Now it's 2020 and if your running Office365 you should really be using the Microsoft Graph API to do this. So what I've done is create a PowerShell Module (and I made it a one file script for those that are more comfortable with that format) that's a port of the EWS script above that is so popular. This script uses the ADAL library for Modern Authentication (which if you grab the library from the PowerShell gallery will come down with the module). Most EWS properties map one to one with the Graph and the Graph actually provides better information on recurrences then...

Downloading a shared file from Onedrive for business using Powershell

I thought I'd quickly share this script I came up with to download a file that was shared using One Drive for Business (which is SharePoint under the covers) with Powershell. The following script takes a OneDrive for business URL which would look like https://mydom-my.sharepoint.com/personal/gscales_domain_com/Documents/Email%20attachments/filename.txt This script is pretty simple it uses the SharePoint CSOM (Client side object Model) which it loads in the first line. It uses the URI object to separate the host and relative URL which the CSOM requires and also the SharePointOnlineCredentials object to handle the Office365 SharePoint online authentication. The following script is a function that take the OneDrive URL, Credentials for Office365 and path you want to download the file to and downloads the file. eg to run the script you would use something like ./spdownload.ps1 ' https://mydom-my.sharepoint.com/personal/gscales_domain_com/Documents/Email%20attachments/filen...

Sending a MimeMessage via the Microsoft Graph using the Graph SDK, MimeKit and MSAL

One of the new features added to the Microsoft Graph recently was the ability to create and send Mime Messages (you have been able to get Message as Mime for a while). This is useful in a number of different scenarios especially when trying to create a Message with inline Images which has historically been hard to do with both the Graph and EWS (if you don't use MIME). It also opens up using SMIME for encryption and a more easy migration path for sending using SMTP in some apps. MimeKit is a great open source library for parsing and creating MIME messages so it offers a really easy solution for tackling this issue. The current documentation on Send message via MIME lacks any real sample so I've put together a quick console app that use MSAL, MIME kit and the Graph SDK to send a Message via MIME. As the current Graph SDK also doesn't support sending via MIME either there is a workaround for this in the future my guess is this will be supported.
All sample scripts and source code is provided by for illustrative purposes only. All examples are untested in different environments and therefore, I cannot guarantee or imply reliability, serviceability, or function of these programs.

All code contained herein is provided to you "AS IS" without any warranties of any kind. The implied warranties of non-infringement, merchantability and fitness for a particular purpose are expressly disclaimed.