Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
### Teams Auto Attendant Holiday Schedule Generator ###
### Version 1.0 ###
### Author: Alexander Holmeset ###
### Email: alexander.holmeset@gmail.com ###
### 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
@Atreidae

This comment has been minimized.

Copy link

@Atreidae Atreidae commented Jan 11, 2020

Looks like the website has added a new class with some whitespace... "Country " all the dates for 2020 appear to have this new class making the script only return 1 holiday (new years day)

I've tested changing line 35 as follows successfully.
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 'country ' } |

image

@darwincr

This comment has been minimized.

Copy link

@darwincr darwincr commented Oct 21, 2020

this worked for me for line 35

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 '} |

@AlexanderHolmeset

This comment has been minimized.

Copy link
Owner Author

@AlexanderHolmeset AlexanderHolmeset commented Oct 22, 2020

this worked for me for line 35

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 '} |

Thanks, a lot darwincr. They keep changing the tagging of the holidays all the time, hard to keep up :-)
There was one small typo in your code change, you wrote $.classname and not $_.classname. Changed that, and your suggestion worked perfectly :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.