Simple and short blogpost this time to help get ready for the holidays. The script reads the holidays for a specified country from officeholidays.com and adds them to a specified Auto Attendant in Teams.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Teams Auto Attendant Holiday Schedule Generator ### | |
### Version 1.0 ### | |
### Author: Alexander Holmeset ### | |
### Email: [email protected] ### | |
### Twitter: twitter.com/alexholmeset ### | |
### Blog: alexholmeset.blog ### | |
#Enter you AutoAttendant ID | |
$AutoAttendantID = "159980fb-ec85-4c3d-b8be-e09a2a17f4eb" | |
#Enter what country you need holidays from. Se valid countries in Mostcountries function. | |
$Country = "Norway" | |
#Function for catching data from officeholidays.com, and convert it to a variable. | |
function Mostcountries { | |
param( | |
[Parameter(Position=0)] | |
[ValidateSet("Algeria","Angola","Armenia","Argentina","Australia","Austria","Azerbaijan","Bahamas","Bahrain","Bangladesh","Barbados","Belarus","Belgium","Bolivia","Bosnia_and_Herzegovina","Botswana","Brazil","Brunei","Bulgaria","Burundi","Cambodia","Canada","Cayman_Islands","Chile","China","Colombia","Costa_Rica", | |
"Croatia","Cyprus","Czech_Republic","Denmark","Dominican_Republic","Ecuador","Egypt","El_Salvador","Estonia","Ethiopia","Fiji","Finland","France","Georgia","Germany","Ghana","Gibraltar","Greece","Grenada","Guernsey", | |
"Honduras","Hong_Kong","Hungary","Iceland","India","Indonesia","Iraq","Ireland","Isle_of_Man","Israel","Italy","Jamaica","Japan","Jersey","Jordan","Kazakhstan","Kenya","Kuwait","Lao", | |
"Latvia","Lebanon","Libya","Liechtenstein","Lithuania","Luxembourg","Macau","Macedonia","Maldives","Malta","Mauritius","Mexico","Moldova","Monaco","Montenegro", | |
"Malaysia","Morocco","Mozambique","Myanmar","Netherlands","New_Zealand","Nigeria","Norway","Oman","Pakistan","Panama","Paraguay","Peru","Philippines","Poland","Portugal","Qatar", | |
"Romania","Russia","Rwanda","Saint_Lucia","Saudi_Arabia","Serbia","Singapore","Slovakia","Slovenia","South_Africa","South_Korea","Spain","Sri_Lanka","Sweden", | |
"Switzerland","Taiwan","Tanzania","Thailand","Tonga","Trinidad_and_Tobago","Tunisia","Turkey","Turks_and_Caicos_Islands","Uganda","Uganda","Ukraine", | |
"United_Arab_Emirates","United_Kingdom","Uruguay","USA","Venezuela","Vietnam","Yemen","Zambia","Zimbabwe")] | |
[System.String]$Country | |
) | |
$uri = "http://www.officeholidays.com/countries/$Country/index.php" | |
$html = Invoke-WebRequest -Uri $uri | |
$tables = $html.ParsedHtml.getElementsByTagName('tr') | | |
Where-Object {$_.classname -eq 'region' -or $_.classname -eq 'country' -or $_.classname -eq 'region-past' -or $_.classname -eq 'country-past' -or $_.classname -eq 'nap-past' -or $_.classname -eq 'govt-past' -or $_.classname -eq 'region ' -or $_.classname -eq 'country ' -or $_.classname -eq 'region-past ' -or $_.classname -eq 'country-past ' -or $_.classname -eq 'nap-past ' -or $_.classname -eq 'govt-past '} | | |
Select-Object -exp innerHTML | |
$script:holidays = foreach ($table In $tables){ | |
$Date = (($table -split 'datetime="')[1] -split '">')[0]; | |
$Title = ((($table -split "<TD><A title=")[1] -split ">")[1] -split "</A")[0] | |
[PSCustomObject]@{ | |
Title = $Title ; Date = $Date | Get-Date -UFormat %d/%m/%Y | |
} | |
} | |
} | |
# | |
$ErrorActionPreference = "SilentlyContinue" | |
Mostcountries -country $Country | |
$holidaylist = @() | |
foreach($holiday in $holidays){ | |
$object = [PSCustomObject]@{ | |
Title = $holiday.Title ; StartDate1 = $holiday.Date | Get-Date -UFormat %d/%m/%Y ; EndDateTime1 = ""; StartDateTime2 = ""; EndDateTime2 = ""; StartDateTime3 = ""; EndDateTime3 = ""; StartDateTime4 = ""; EndDateTime4 = ""; StartDateTime5 = ""; EndDateTime5 = ""; StartDateTime6 = ""; EndDateTime6 = ""; StartDateTime7 = ""; EndDateTime7 = ""; StartDateTime8 = ""; EndDateTime8 = ""; StartDateTime9 = ""; EndDateTime9 = ""; StartDateTime10 = ""; EndDateTime10 = "" | |
} | |
$holidaylist += $object | |
} | |
$holidaylist | Export-Csv -Path C:\temp\Holidays.csv -Encoding UTF8 | |
$bytes = [System.IO.File]::ReadAllBytes("C:\temp\Holidays.csv") | |
#Import-CsAutoAttendantHolidays -Identity $AutoAttendantID -Input $bytes |
[…] https://alexholmeset.blog/2019/12/10/teams-auto-attendant-holiday-schedule-generator/ […]
LikeLike
Hi Alex,
Fantastic blog post!
i found many of the holidays generated fall on a weekend which makes them redundant if the AA / CQ only operates on a weekday.
Any chance these can somehow be excluded?
Thanks again!
Michael
LikeLike
Thanks.
Yeah, just need to have a logic to check if its saturday/sunday
LikeLike