Change Business Hours of a Teams Auto Attendant with PowerShell

--

Changing the business hours on a Teams Auto Attendant can be quite cumbersome. Especially if you have multiple hours a day, like a lunch break. If you’ve been working long enough with Teams, you probably remember how easy it was in Skype for Business Online Admin Center. There, we could just select opening hours from a timetable and be done with it. Nowadays we have to select the start and end time from a drop-down list for each day individually.

Screenshot of Teams Admin Center displaying the configuration of an after hours call flow.

To speed up this process, I’ve created a PowerShell Script. Right now, there are no parameters. After all, the idea is to be quicker and not make you pick times from a drop-down in PowerShell rather than in TAC.

By default, the script will allow you to set a time range for mornings and one for afternoons. These are defined in the variables $tr1 and $tr2 on line 7 and 8. You can adjust them to your liking, as long as they don’t overlap each other. Only 15minute increments are supported. You must use the 24-hour clock system.

Edit (08.09.2022): I’ve updated line 16 to look for the CallFlowId of the Auto Attendants CallHandlingAssociation with type “AfterHours” instead of the CallFlow Name matching “After hours call flow”.

Once you run the script, the defined time ranges will be applied to the Auto Attendant which was selected from the list.

This works for both, Auto Attendants which already have business hours configured and Auto Attendants which didn’t have business hours already. Your configured after hours call flow (e.g. forward to shared voicemail etc.) will not be impacted/overwritten. It will stay exactly the same as it was.

If your call flow has different business hours for specific days, just add more $tr variables and make sure to add/change them on line 40. For example, if your business closes early on Fridays but has no lunch break, create a $tr3 variable and change -FridayHours @($tr1,$tr2) to -FridayHours @($tr3) .

By default, the script will not add any business hours for Saturday and Sunday. This means that the after hours call flow will be active on the weekend. If you also want to configure hours for these days, add them using the switch -SaturdayHours followed by the array @($tr4,$tr5) .

On a final note, when changing business hours via PowerShell, we must use the -Complement switch. This will invert the time ranges. Meaning that the after hours call flow will be active during times which are outside of what is shown on the timetable. TAC displays the business hours, during which the Auto Attendant is open but it does so on the after hours call flow page. This can be a little misleading. When business hours are set through TAC, the complement flag is automatically enabled.

I hope this helps you save some time as well.

--

--

Martin Heusser | M365 Apps & Services MVP

I 'm a Microsoft MVP and work as a Microsoft Teams Voice Engineer. I like to share my knowledge about Teams, Power Automate, Azure and PowerShell on Medium.