Thursday, March 02, 2006

Updating appointments that are 1 hour out because of the Commonwealth Games Timezone Changes

Since i posted this last month I had a few questions around updating appointments that appear 1 hour out after you have updated the Timezone patch for the Commonwealth games. Firstly the only supported method of updating affected appointment is in which is to export the appointments in the overlap period to a text file, delete the appointments and then re-import those appointments.

One completely unsupported method to update appointments is to use CDOEX and Exoledb to move the appointment times one hour into the past for appointments that exists in the overlap period. One issue with using this method is that if you have any reoccurring appointments that have been expanded within the overlap period then changing the date and time on these instances of the recurring appointments will break the recursion on that instance of the expanded appointment so although outlook will show the appointment now occurs at the right time is will show the circle with the cross through it to indicate this appointment is an exception to the normal recurrence of the appointment. The other issue is that apart from myself this method hasn’t been really tested so there may be some other potential snags. But if you’re looking for something to test in a development environment to see if you can fix this problem this script could come in handy. The other problem is there has now been a patch released for home users that modifies the current timezone instead of adding a new time-zone. Its recommended that you don’t use this patch if you use Exchange or OWA and its quite possible that machines will have this patch applied and have created appointments that appear correct with the old timezone data. In this case running this script would actually make those appointments appear wrongly. You really need to be aware of how your machines have been patched before contemplating a fix.

The Script

Before you run the fix script I recommend you run a scan using another script I posted here. This will give you a list of all the appointments that are in the affected overlap period and which appointments will be modified by the script. The fix script queries for appointments within the overlap period that appear to be created from machines that haven’t had the patch applied or from OWA where the Timezone has been updated in the options. By looking at the urn:schemas:calendar:timezoneid property or the{00062002-0000-0000-C000-000000000046}/0x8234 mapi property. The script then shifts the time of the appointment back one hour by adjusting the start and end times and updates the timezone information so that if the script is run again it wont modify the appointments for a second time.

Before using the script you need to update the domainname variable within the script to reflect the default SMTP domain name you are using eg

domainname = ""

The script uses Exoldb so it needs to be run from the server where the mailbox is located. The script is designed to be run on one mailbox at a time so to run the script you need to enter the mailbox you what to run it against as a commandline parameter eg cscript gapchangeex.vbs username. As stated before don’t run this script in production unless you have thoroughly tested it.

I’ve posted a copy of the script here the script itself looks like

user = wscript.arguments(0)
Set fso = CreateObject("Scripting.FileSystemObject")
fname = "c:\" & wscript.arguments(0) & ".csv"
set wfile = fso.opentextfile(fname,2,true)
wfile.writeline("User,Subject,UTC timestart,UTC timeend, InstanceType,
public datefrom
public dateto
datefrom = "2006-03-26T10:00:00Z"
dateto = "2006-04-02T10:00:00Z"
domainname = ""
sConnString = "file://./backofficestorage/" & domainname
sConnString = sConnString & "/mbx/" & user & "/calendar"
call QueryCalendarFolder(sConnString,user)

wscript.echo "Done"

Public Sub QueryCalendarFolder(sConnString,user)
SSql = "SELECT ""DAV:href"", ""DAV:parentname"", ""urn:schemas:calendar:timezoneid"",
""urn:schemas:httpmail:subject"", "
SSql = SSql & """{00062002-0000-0000-C000-000000000046}/0x8234"",
""urn:schemas:calendar:timezone"", "
SSql = SSql & """urn:schemas:calendar:instancetype"", ""urn:schemas:calendar:dtstart""
, ""urn:schemas:calendar:dtend"" "
SSql = SSql & "FROM scope('shallow traversal of """ & sConnString & """') "
SSql = SSql & " Where ""DAV:isfolder"" = false AND ""DAV:ishidden"" = false "

SSql = SSql & "AND ""urn:schemas:calendar:dtend"" > CAST(""" & datefrom & """ as
'dateTime') " _
& "AND ""urn:schemas:calendar:dtstart"" < CAST(""" & dateto & """ as 'dateTime')"

Set oConn = CreateObject("ADODB.Connection")
oConn.Provider = "Exoledb.DataSource"
oConn.Open sConnString
Set oRecSet = CreateObject("ADODB.Recordset")
oRecSet.CursorLocation = 3
oRecSet.Open sSQL, oConn.ConnectionString
if err.number <> 0 then wfile.writeline(user & "," & "Error Connection to
While oRecSet.EOF <> True
select case oRecSet.fields("{00062002-0000-0000-C000-000000000046}/0x8234").value
case "(GMT+10:00) Canberra, Melbourne, Sydney" susapt = 1
upto = "(GMT+10:00) Canberra, Melbourne, Sydney (Commonwealth Games)"
case "(GMT+09:30) Adelaide" susapt = 1
upto = "(GMT+09:30) Adelaide (Commonwealth Games)"
case "(GMT+10:00) Hobart" susapt = 1
upto = "(GMT+10:00) Hobart (Commonwealth Games)"
case "(GMT+10:00) Canberra, Melbourne, Sydney (Commonwealth Games)" susapt = 2
case "(GMT+09:30) Adelaide (Commonwealth Games)" susapt = 2
case "(GMT+10:00) Hobart (Commonwealth Games)" susapt = 2
end select
select case oRecSet.fields("urn:schemas:calendar:timezoneid").value
case "78" susapt = 2
case "79" susapt = 2
case "80" susapt = 2
case "57" susapt = 1
uptoid = "78"
case "19" susapt = 1
uptoid = "79"
case "42" susapt = 1
uptoid = "80"
end select
if susapt = 0 then
if instr(oRecSet.fields("urn:schemas:calendar:timezone").value,"TZID:GMT +0930")
susapt = 1
upto = "(GMT+09:30) Adelaide (Commonwealth Games)"
end if
if instr(oRecSet.fields("urn:schemas:calendar:timezone").value,"TZID:GMT +1000")
susapt = 1
upto = "(GMT+10:00) Canberra, Melbourne, Sydney (Commonwealth Games)"
end if

end if
if susapt = 1 then
Wscript.echo User
wscript.echo oRecSet.fields("DAV:Href").value
wscript.echo oRecSet.fields("urn:schemas:httpmail:subject").value
wscript.echo oRecSet.fields("{00062002-0000-0000-C000-000000000046}/0x8234").value
wscript.echo oRecSet.fields("urn:schemas:calendar:timezoneid").value
wscript.echo oRecSet.fields("urn:schemas:calendar:instancetype").value
wfile.writeline(user & "," &
oRecSet.fields("urn:schemas:httpmail:subject").value & ","_
& oRecSet.fields("urn:schemas:calendar:dtstart").value & "," &
oRecSet.fields("urn:schemas:calendar:dtend").value _
& "," & oRecSet.fields("urn:schemas:calendar:instancetype").value & "," _
& replace(replace(oRecSet.fields("{00062002-0000-0000-C000-000000000046}/0x8234").value,vbcrlf,""),",","")
& "," & oRecSet.fields("urn:schemas:calendar:timezoneid").value)
set apptobj = createobject("ADODB.Record") cstr(oRecSet.fields("DAV:HREF").value),,3
wscript.echo dateadd("h",-1,oRecSet.Fields("urn:schemas:calendar:dtstart").value)
apptobj.Fields("urn:schemas:calendar:dtstart").value = dateadd("h",-1,oRecSet.Fields("urn:schemas:calendar:dtstart").value)
apptobj.Fields("urn:schemas:calendar:dtend").value = dateadd("h",-1,oRecSet.Fields("urn:schemas:calendar:dtend").value)
if uptoid <> "" then apptobj.Fields("urn:schemas:calendar:timezoneid").value =
if upto <> "" then apptobj.Fields("{00062002-0000-0000-C000-000000000046}/0x8234").value
= upto
uptoid = ""
upto = ""
end if
susapt = 0
Set oRecSet = Nothing
Set oConn = Nothing
End Sub

No comments: