Public/Get-P2000Entry.ps1
# .SYNOPSIS # Retrieves P2000 emergency services notifications function Get-P2000Entry { [CmdletBinding(DefaultParameterSetName = 'All')] param ( [Parameter(ParameterSetName = 'Province')] [ValidateSet('groningen', 'friesland', 'drenthe', 'overijssel', 'flevoland', 'gelderland', 'utrecht', 'noord-holland', 'zuid-holland', 'zeeland', 'noord-brabant', 'limburg')] [string]$Province, [Parameter(ParameterSetName = 'Region')] [ValidateScript( { (Get-P2000Region).ID -contains $_ } )] [string]$Region, [Parameter(ParameterSetName = 'Postcode')] [ValidatePattern('\d{4}')] [string]$PostCode ) $Uri = switch ($PSCmdlet.ParameterSetName) { 'Province' { "https://www.alarmfase1.nl/provincie/$Province/" } 'Region' { "https://www.alarmfase1.nl/$Region/" } 'Postcode' { "https://www.alarmfase1.nl/postcode/$PostCode/" } 'All' { 'https://www.alarmfase1.nl/' } } Invoke-WebRequest -Uri $Uri | Select-Object -ExpandProperty Content | pup '.call json{}' | ConvertFrom-Json | ForEach-Object { $Properties = [Ordered]@{ } $Properties.Latitude = $_.Latitude $Properties.Longitude = $_.Longitude $Properties.Service = $_.Service if ($_.Children[0]) { if ($_.Children[0].Children[0]) { $Properties.DateTimeText = $_.Children[0].Children[0].content try { $Properties.DateTime = [DateTime]::ParseExact($_.Children[0].Children[0].content + ':00', 's', $null) $Properties.DateTimeUtc = [System.TimeZoneInfo]::ConvertTimeBySystemTimeZoneId($Properties.DateTime, 'Europe/Amsterdam', 'UTC') } catch { } } if ($_.Children[0].Children[1]) { $Properties.Link = $_.Children[0].Children[1].href $Properties.ID = ($Properties.Link -split '/')[-2] if ($_.Children[0].Children[1].Children[0]) { $Properties.Title = $_.Children[0].Children[1].Children[0].text } } } if ($_.Children[1]) { $Properties.Original = $_.Children[1].text $Properties.Priority = if ($Properties.Original -match '^(?<Priority>\w\d)\s') { $Matches['Priority'] } else { '' } } if ($_.Children[2]) { if ($_.Children[2].Children[1]) { if ($_.Children[2].Children[1].Children[3]) { $Properties.Address = $_.Children[2].Children[1].Children[3].text } if ($_.Children[2].Children[1].Children[1]) { if ($_.Children[2].Children[1].Children[1].Children[0]) { $Properties.City = $_.Children[2].Children[1].Children[1].Children[0].text } } if ($_.Children[2].Children[1].Children[2]) { if ($_.Children[2].Children[1].Children[2] | Get-Member Children -MemberType NoteProperty) { $Properties.PostCode = $_.Children[2].Children[1].Children[2].Children[0].text } } if ($_.Children[2].Children[1].Children[0]) { $Properties.Province = ($_.Children[2].Children[1].Children[0].href -split '/')[4] } } } $Properties.PSTypeName = 'UncommonSense.P2000.Entry' [pscustomobject]$Properties } } |