A PowerShell function to return UK Bank Holidays.
function Get-BankHolidaysUK { param ( [int] $Year = (Get-Date).Year, [ValidateSet("england-and-wales", "scotland", "northern-ireland")] [string] $country = 'scotland' ) $govParams = @{ uri = "https://www.gov.uk/bank-holidays.json" UseBasicParsing = $True } $data = $(invoke-webrequest @govParams).content $json = ConvertFrom-Json $data| Select-Object -expandproperty $country $bankhols = Select-Object -inputObject $json -expandproperty events $bankhols | Select-Object -property date,title | where { ($_.date).substring(0,4) -eq $Year } $bankholidays }
Get-BankHolidaysUK -Year '2024' -country "england-and-wales"
date title ---- ----- 2024-01-01 New Year’s Day 2024-03-29 Good Friday 2024-04-01 Easter Monday 2024-05-06 Early May bank holiday 2024-05-27 Spring bank holiday 2024-08-26 Summer bank holiday 2024-12-25 Christmas Day 2024-12-26 Boxing Day
“Why do we travel to remote locations? To prove our adventurous spirit or to tell stories about incredible things? We do it to be alone amongst friends and to find ourselves in a land without man” ~ George Mallory (Mountain climber)
invoke-WebRequest - Get content from a web page on the Internet.
ConvertFrom-Json - Convert a JSON-formatted string to a custom object.
How-To: Calculate the date of Easter.