Here is a PowerShell function that gets all German holidays, either nationwide or just for your state:
function Get-GermanHoliday { param ( [int] $Year = (Get-Date).Year, [ValidateSet("BB","BE","BW","BY","HB","HE","HH","MV","NATIONAL", "NI","NW","RP","SH","SL","SN","ST","TH")] [string] $State = 'NATIONAL' ) $url = "https://feiertage-api.de/api/?jahr=$Year" $holidays = Invoke-RestMethod -Uri $url -UseBasicParsing $holidays.$State }
Run the function above, then either run the command as-is:
PS> Get-GermanHoliday Neujahrstag : @{datum=2023-01-01; hinweis=} Karfreitag : @{datum=2023-04-07; hinweis=} Ostermontag : @{datum=2023-04-10; hinweis=} Tag der Arbeit : @{datum=2023-05-01; hinweis=} Christi Himmelfahrt : @{datum=2023-05-18; hinweis=} Pfingstmontag : @{datum=2023-05-29; hinweis=} Tag der Deutschen Einheit : @{datum=2023-10-03; hinweis=} 1. Weihnachtstag : @{datum=2023-12-25; hinweis=} 2. Weihnachtstag : @{datum=2023-12-26; hinweis=}
Or, submit additional arguments to get specific holidays for a given state:
PS> Get-GermanHoliday -State ni -Year 2023
Let’s assume you want to know the date for the German holiday “Christi Himmelfahrt”. Here is how you could get to that information:
# specify the name of the holiday to look up $holidayName = 'Christi Himmelfahrt' # get all holiday information $holidays = Get-GermanHoliday # get the particular holiday we are after, read the property "datum" # and convert the string ISO format to a real DateTime: $date = $holidays.$holidayName.datum -as [DateTime] $date