public/Get-FootballFixtureEvent.ps1

function Get-FootballFixtureEvent {
    <#
        .EXAMPLE
            Get-FootballFixtureEvent -Header $Headers -Token $Token -FixtureId 19134951 -Event goal
         
    #>

    [CmdletBinding()]
    param(

        [Parameter(Mandatory=$true)]
        [ValidateNotNullOrEmpty()]
        [Object]$Header,

        [Parameter(Mandatory=$true)]
        [ValidateNotNullOrEmpty()]
        [string]$FixtureId,

        [Parameter(Mandatory=$true)]
        [ValidateNotNullOrEmpty()]
        [string]$Token

    )
    process{

        $ErrorActionPreference = 'Stop'

        try {

            $TypeUri = "https://api.sportmonks.com/v3/football/fixtures/$($FixtureId)?api_token=$Token&include=scores;participants;statistics.type;events"
            $TypeResponse = Invoke-RestMethod $TypeUri -Method 'GET' -Headers $Header
            $ResponseData = $($TypeResponse.data)
            $FixtureParticipants = $($ResponseData.participants)
            $FixtureEvents =@()

            foreach ($FixtureParticipant in $FixtureParticipants) {

                $FixtureGoalEvents = $($ResponseData.events) | Where-Object {$_.participant_id -eq $($FixtureParticipant.id)}

                if ($FixtureGoalEvents) {

                    $ParticpantObject = $FixtureGoalEvents.PSObject.Copy()
                    $ParticpantObject | Add-Member -MemberType NoteProperty -Name participant_name -Value $($FixtureParticipant.name)
                    $ParticpantObject | Add-Member -MemberType NoteProperty -Name fixture_name -Value $($ResponseData.name)
                    $ParticpantObject | Add-Member -MemberType NoteProperty -Name result_info -Value $($ResponseData.result_info)
                    $ParticpantObject | Add-Member -MemberType NoteProperty -Name starting_at -Value $($ResponseData.starting_at)
                    $FixtureEvents += $ParticpantObject

                } # if
             
            } # foreach

            return $FixtureEvents

        }
        catch {

            throw "$($MyInvocation.MyCommand.Name): $_.Exception.Message"

        } # try catch

    } # process

} # function