Public/Get-P2000Entry.ps1
# .SYNOPSIS # Retrieves P2000 emergency services notifications function Get-P2000Entry { [CmdletBinding(DefaultParameterSetName = 'All')] param ( [Parameter(Mandatory,ParameterSetName = 'Province')] [ValidateSet('groningen', 'friesland', 'drenthe', 'overijssel', 'flevoland', 'gelderland', 'utrecht', 'noord-holland', 'zuid-holland', 'zeeland', 'noord-brabant', 'limburg')] [string]$Province, [Parameter(Mandatory,ParameterSetName = 'Region')] [Parameter(Mandatory,ParameterSetName = 'City')] [ValidateScript( { (Get-P2000Region).ID -contains $_ } )] [string]$Region, [Parameter(Mandatory,ParameterSetName = 'City')] [ValidateScript({(Get-P2000City -Region $Region).ID -contains $_})] [string]$City, [Parameter(Mandatory,ParameterSetName = 'Postcode')] [ValidatePattern('\d{4}')] [string]$PostCode ) $Uri = switch ($PSCmdlet.ParameterSetName) { 'Province' { "https://www.alarmfase1.nl/provincie/$Province/" } 'Region' { "https://www.alarmfase1.nl/$Region/" } 'City' { "https://www.alarmfase1.nl/$Region/$City/" } 'Postcode' { "https://www.alarmfase1.nl/postcode/$PostCode/" } 'All' { 'https://www.alarmfase1.nl/' } } ConvertTo-HtmlDocument -Uri $Uri | Select-HtmlNode -CssSelector '.call' -All | ForEach-Object { $Properties = [Ordered]@{ } $Properties.Latitude = $_.Attributes['Latitude'].Value $Properties.Longitude = $_.Attributes['Longitude'].Value $Properties.Service = $_.Attributes['Service'].Value $Properties.DateTimeText = ($_ | Select-HtmlNode -CssSelector 'span').Attributes['content'].Value try { $Properties.DateTime = [DateTime]::ParseExact($Properties.DateTimeText + ':00', 's', $null) $Properties.DateTimeUtc = [System.TimeZoneInfo]::ConvertTimeBySystemTimeZoneId($Properties.DateTime, 'Europe/Amsterdam', 'UTC') } catch { } $Properties.Link = ($_ | Select-HtmlNode -CssSelector 'a').Attributes['href'].Value $Properties.ID = ($Properties.Link -split '/')[-2] $Properties.Title = ($_ | Select-HtmlNode -CssSelector 'b').InnerText $Properties.Original = ($_ | Select-HtmlNode -CssSelector 'pre').InnerText $Properties.Priority = if ($Properties.Original -match '^(?<Priority>\w\d)\s') { $Matches['Priority'] } else { '' } $Properties.Address = ($_ | Select-HtmlNode -CssSelector 'span[itemprop="streetAddress"]').InnerText $Properties.PostCode = ($_ | Select-HtmlNode -CssSelector 'span[itemprop="postalCode"]').InnerText $Properties.City = ($_ | Select-HtmlNode -CssSelector 'span[itemprop="addressLocality"]').InnerText $Properties.Province = (($_ | Select-HtmlNode -CssSelector 'p[itemprop="address"] a').Attributes['href'].Value -split '/')[4] $Properties.PSTypeName = 'UncommonSense.P2000.Entry' [pscustomobject]$Properties } } |