Synchronizing Office365 calendars with the web

Balmer salute

Hello. Today I’m writing about a different version of a powershell utility script I made before for calendar synchronization. See that post for details and bottom of it for a raging update. This is a continued post from before.
That script I made before was for an Exchange server and it was working great at the time. But later we switched to Office365 and since April it became broken in a way that was making me wanna pull my hair out. However thanks to my persistence and a nudge into the right direction from some people just when I was about to give up, I was able to make that script work again, so in turn I made it as a different script and named it v2. The old one can still be found here.

Now the thing here to understand, is that O365 cloud is great, it offers lots of awesome things. But if you’re an administrator who wants to automate some stuff and need to dig deeper into the core of it all, then prepare for a world of pain.
Don’t get me wrong though – the API docs are good enough for general purpose coding tasks and there are many good code samples to learn from, but some specific things lack documentation and here I’ll describe how I made my script work again. Read the first post for a detailed problem description.

The new script can be found in my projects folder, here.

For the modification reference, I used the unofficial microsoft script for calendar synchronization.

Now what did I change exactly to make it work again? just a few things.

The first thing you’ll notice is that you need to provide credentials now. The next thing is a callback for redirection URL validation. That block is needed for AutodiscoverUrl() and Exchange schema version was also changed to “Exchange2010_SP2”. After that, appointment logic is left as it was, but at the very end where it saves an appointment, “[Microsoft.Exchange.WebServices.Data.SendInvitationsMode]::SendToNone” attribute had to be added, otherwise the script wouldn’t work. Now this is the most interesting part, because that parameter is optional in the .Save() function, however if you don’t provide that parameter, then it won’t work – it has to be there.

And that is pretty much it – just these few things had to be added… after 2 weeks of live testing, it all seems to be working great.

UPDATE 2017.05.01: I have optimized this script a a bit. Somehow I didn’t think to make the script get all appointments from the calendar when checking for changes, and not get one item at a time. This reduced the script execution time (in my case) from over 2 hours to mere 4 minutes – DAYUM suhn!

Leave a Reply

Your email address will not be published. Required fields are marked *