Public/Get-Weather.ps1

<#
.EXAMPLE
Get-Weather -Latitude 52.3 -Longitude 3.4 -Units metric -Language nl -ApiKey 279c1fbf493f93d8eaa9a56cf225a23d
#>

function Get-Weather
{
    param
    (
        [Parameter(Mandatory, Position = 0)]
        [ValidateRange(-90, 90)]
        [decimal]$Latitude,

        [Parameter(Mandatory, Position = 1)]
        [ValidateRange(-180, 180)]
        [decimal]$Longitude,

        [ValidateSet('standard', 'metric', 'imperial')]
        [string]$Units = 'standard',

        [ValidateSet('en', 'nl')]
        [string]$Language,

        [ValidateNotNull()]
        [string]$ApiKey,

        [switch]$Raw
    )

    $Url = 'https://api.openweathermap.org/data/3.0/onecall?lat={0}&lon={1}&units={2}&lang={3}&appid={4}' -f $Latitude, $Longitude, $Units, $Language, $ApiKey
    Write-Verbose "Using url $Url"

    if ($Raw)
    {
        Invoke-WebRequest -Uri $Url | Select-Object -ExpandProperty Content
    }
    else
    {
        $Response = Invoke-RestMethod -Uri $Url

        $TemperatureUnit = switch ($Units)
        {
            'standard' { 'K' }
            'metric' { 'ºC' }
            'imperial' { 'ºF' }
        }

        $TimeZoneOffset = [TimeSpan]::FromSeconds($Response.timezone_offset)

        [PSCustomObject]@{
            PSTypeName      = 'UncommonSense.Weather'
            Latitude        = $Response.lat
            Longitude       = $Response.lon
            TemperatureUnit = $TemperatureUnit
            TimeZone        = $Response.timezone
            TimeZoneOffset  = $TimeZoneOffset
            Current         = $Response.current | Convert-Current -TimeZoneOffset $TimeZoneOffset -TemperatureUnit $TemperatureUnit
            Minutely        = $Response.minutely | Convert-Minutely -TimeZoneOffset $TimeZoneOffset
            Hourly          = $Response.hourly | Convert-Hourly -TimeZoneOffset $TimeZoneOffset -TemperatureUnit $TemperatureUnit
            Daily           = $Response.daily | Convert-Daily -TimeZoneOffset $TimeZoneOffset
            Alerts          = $Response.alerts ?? @() | Convert-Alert -TimeZoneOffset $TimeZoneOffset
        }
    }
}