Public/Get-DunePatchingWindowAssignment.ps1

function Get-DunePatchingWindowAssignment {
    [CmdletBinding(DefaultParameterSetName = "Default")]
    param (
        [Parameter(ParameterSetName = "Id")]
        [guid]$Id,

        [Parameter(ParameterSetName = "ResourceGroup", ValueFromPipeline)]
        [DuneResourceGroup]$ResourceGroup,

        [Parameter(ParameterSetName = "PatchingWindow")]
        [guid]$ResourceGroupId,

        [Parameter(ParameterSetName = "PatchingWindow", ValueFromPipeline)]
        [DunePatchingWindow]$PatchingWindow,

        [Parameter(ParameterSetName = "ResourceGroup")]
        [guid]$PatchingWindowId,

        [Parameter()]
        [switch]$Raw
    )

    begin {
        Write-Debug "$($MyInvocation.MyCommand)|begin"
        $ReturnObjects = @()
        $ProcessedUrls = @()
        $BaseUri = "patching/windows/assignments"
        $Method = "GET"
    }

    process {
        Write-Debug "$($MyInvocation.MyCommand)|process|$($PSCmdlet.ParameterSetName)"

        # Build Uri
        switch ($PSCmdlet.ParameterSetName) {
            'Id' { $Uri = '{0}?Id={1}' -f $BaseUri, $Id }
            'ResourceGroup' {
                $Uri = '{0}?ResourceGroupId={1}' -f $BaseUri, $ResourceGroup.Id
                if ($PatchingWindowId) { $Uri, "PatchingWindowId=$PatchingWindowId" -join "&" }
            }
            'PatchingWindow' {
                $Uri = '{0}?PatchingWindowId={1}' -f $BaseUri, $PatchingWindow.id
                if ($ResourceGroupId) { $Uri, "ResourceGroupId=$ResourceGroupId" -join "&" }
            }
            Default { $Uri = $BaseUri }
        }

        # ApiCall Cache
        if ($ProcessedUrls -notcontains $Uri) {
            try {
                # ApiCall and Object conversion
                $Response = Invoke-DuneApiRequest -Uri $Uri -Method $Method
                $ProcessedUrls += $Uri
                $Results = if ($Response.Content) { $Response.Content | ConvertFrom-Json }
                $ReturnObjects += $Results.items | ForEach-Object {
                    if ($Raw) {
                        $_
                    }
                    else {
                        ConvertTo-DuneClassObject -Class DunePatchingWindowAssignment -InputObject $_
                    }
                }
            }
            catch {
                throw $_
            }
        }
        else {
            Write-Debug "$($MyInvocation.MyCommand)|process|ApiCall Cache hit: DuneApiRequest for $Uri already invoked"
        }
    }

    end {
        Write-Debug "$($MyInvocation.MyCommand)|end"
        return $ReturnObjects
    }
}