Contents

Add holidays to Teams Phone in an automated way

Adding holidays to Teams in an automated way

A quick blogpost today, leveraging some PowerShell goodness.

In a recent project, I was setting up Teams Phone System. One of the regular maintenance tasks in day to day operation, is making sure the opening hours set in the callflows (with your Auto Attendants) match the actual working hours of your business. One of the features here is the use of ‘holidays’, to specify days on which the Auto Attendant will not follow the regular opening hours, but will use a seperately defined schedule in stead.

You set these holidays through the interface, based on dates. These dates include the years, so for holidays that occur on the same date each yeer, you’ll need to set them every year like new. There sould be a way to automate this, right? There is!

Solution

When setting up the automation, my first quest was for a API I could use to get the actual holidays. I found one in date.nager.at. The site has soe excellent documentation for using the API, so it’s easy to create the actual query: https://date.nager.at/api/v3/publicholidays/2024/NL The query includes the year (2024) and the country (NL), so it should be easy for you create a matching query for your own situation.

After getting the data, the next step will be importing the dates into Teams. Of course, we use the MicrosoftTeams PowerShell module for this. Setting up the holidays is a two-step process. First, we need to define the actual date rang (which can span multple days if you have the need to do so). We can do that using the New-CSOnlineDateTimeRange cmdlet. After that, we use the newly created range to create the actual holiday schedule, using New-CSOnlineSchedule. The cmdlets for creating the range and for setting up the schedule are well documented, so after fiddling with the format a bit we can create a fairly simple script:

1
2
3
4
5
6
$holidays = Invoke-WebRequest https://date.nager.at/api/v3/publicholidays/2024/NL | ConvertFrom-Json
foreach ($holiday in $holidays) {
    $daterange = New-CsOnlineDateTimeRange -Start (Get-Date $holiday.date -Format 'd/M/yyyy')
    $holidayname = $holiday.localname + '-' + (Get-Date $holiday.date -Format 'yyyy')
    New-CsOnlineSchedule -Name $holidayname -FixedSchedule -DateTimeRanges @($daterange)
}

This script wil fetch all the holidays for the given year and country and iterates through this collection to create the DateTimeRange for each entry, followd by adding this date to the schedule.

Usage

Of course, you can adjust this code snippet to your liking. Set up different countries or years by adjusting the API-call, or maybe add something to the holiday name so you can easily identify and delete them at the end of the year? Once again, PowerShell is your friend ;)