How to Populate Teams Holiday Dates with PowerShell

Create Teams Holidays from a Data File

As we approach the end of the year, thoughts turn to system housekeeping and annual maintenance tasks. If your organization uses the Teams Phone system, you might want to populate holiday data to handle dates when people won’t be working and alternative arrangements will be in place to handle inbound calls. This article discusses how to use a data file to hold information about holidays that is read by a PowerShell script to update Teams about new holidays.

This ground has been covered before in different ways, mostly handling the automated download of holiday data from internet sources to create events for a single year. I wanted to create a general-purpose solution that could handle different countries and different years. If you can populate a CSV file with event data, you can use the script described here.

Multiple Events of the Same Type in Different Years

Teams allows multiple events to be created for the same date. I’m sure that this is because multiple events do occur on the same day, especially in different countries where multinational organizations operate, but it’s something to guard against. One way of handling the issue is to use a suffix with events. For example:

New Year’s Day (WW) is a world-wide event on 1 January of each year.

St. Patrick’s Day (IRL) is an Irish public holiday on 17 March each year.

The decision how to name events is highly organization-specific and depends on the countries where the organization operates and if business continues during different events. For the purpose of this example, I decided to use a simple year suffix to allow the script to process multiple events of the same type for different years. Accordingly, the input CSV file looks like that shown in Figure 1.

Teams holiday data in a CSV file
Figure 1: Teams holiday data in a CSV file

You can populate the file manually or retrieve the data from an external source (here’s an example for Australia). In my case, the data covers Irish public holidays for a couple of years, which is enough to illustrate the principal.

It’s easy to maintain Teams holiday data through the Teams admin center. However, that implies access to the Teams admin center, which might not be available to the person who looks after company holiday information. This person can simply update the CSV file and hand it over to an administrator for processing. Another advantage of this approach is that you can continue to add new events to the file. Each time the script runs, code checks for existing events and ignores those already in Teams before adding the new items.

Steps in the Script

The steps in the script (which uses cmdlets from the Microsoft Teams PowerShell module) are:

  • Fetch the current Teams holiday schedule using the Get-CsOnlineSchedule cmdlet.
  • Build a hash table of existing holiday. The table is used to check if an event is already known to Teams.
  • Read in the Teams holiday data from the CSV file into an array.
  • Loop through the array and check each event against the hash table. If Teams doesn’t know about a holiday, process it by creating a date range variable with the New-CsOnlineDateTimeRange cmdlet. As these are all single-day events, only the start date is required. After calculating a date range for the event, add it to Teams with the New-CsOnlineSchedule cmdlet.
  • Read the updated Teams holiday schedule after adding the new events and display the information to the user. The data should be the same as displayed in the Teams admin center (Figure 2).

Teams holiday data displayed in the Teams admin center
Figure 2: Teams holiday data displayed in the Teams admin center

You can download the script from GitHub. Remember, this is a script to illustrate how to approach a problem rather than a complete solution. Adapt and extend the code to meet the needs of your organization.

PowerShell Proves its Worth

An arguable case exists that using PowerShell to automate something simple like adding a few holiday dates to Teams is overkill. That’s possibly true, but a counter-case also exists that writing a script once means the consistent update of Teams holiday data over the years. The point is that PowerShell can do the job if you want it to. Feel free to continue with manual event updates!

Learn how to exploit the data available to Microsoft 365 tenant administrators through the Office 365 for IT Pros eBook. We love figuring out how things work.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.