Public/Get-DuneResourceProvider.ps1

function Get-DuneResourceProvider {
    [CmdletBinding(DefaultParameterSetName = "Default")]
    param (
        [Parameter(Position = 0)]
        [string]$Name,

        [Parameter(ParameterSetName = "Id")]
        [guid]$Id,

        [Parameter(ParameterSetName = "ResourceProviderId", ValueFromPipelineByPropertyName)]
        [guid]$ResourceProviderId,

        [Parameter()]
        [string]$DisplayName,

        [Parameter()]
        [Environments]$DefaultEnvironment,

        [Parameter()]
        [Environments[]]$AllowedEnvironments,

        [Parameter()]
        [string]$Type,

        [Parameter()]
        [switch]$Raw,

        [Parameter()]
        [switch]$IncludeDeleted
    )

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

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

        # Build Uri
        $Uri = switch ($PSCmdlet.ParameterSetName) {
            'Id' { $BaseUri, $Id -join '/' }
            'ResourceProviderId' { $BaseUri, $ResourceProviderId -join '/' }
            Default { $BaseUri }
        }
        if ($Name) {
            $Uri = $Uri | Add-UriQueryParam "NameILike=$Name" -ConvertWildcards
        }
        if ($DisplayName) {
            $Uri = $Uri | Add-UriQueryParam "DisplayNameILike=$DisplayName" -ConvertWildcards
        }
        if ($Type) {
            $Uri = $Uri | Add-UriQueryParam "TypeILike=$Type" -ConvertWildcards
        }
        if ($PSBoundParameters.ContainsKey('DefaultEnvironment')) {
            $Uri = $Uri | Add-UriQueryParam "DefaultEnvironment=$($DefaultEnvironment.ToString)" -ConvertWildcards
        }
        if ($IncludeDeleted) {
            $Uri = $Uri | Add-UriQueryParam "IncludeDeleted=1"
        }

        # 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 }
                if ($PSCmdlet.ParameterSetName -notin 'Id', 'ResourceProviderId') { $Results = $Results.Items } # list endpoint returns content in items property
                $ReturnObjects += $Results | ForEach-Object {
                    if ($Raw) {
                        $_
                    }
                    else {
                        ConvertTo-DuneClassObject -Class DuneResourceProvider -InputObject $_
                    }
                }
            }
            catch {
                throw $_
            }
        }
        else {
            Write-Debug "$($MyInvocation.MyCommand)|process|ApiCall Cache hit: DuneApiRequest for $Uri already invoked"
        }
    }

    end {
        Write-Debug "$($MyInvocation.MyCommand)|end"
        # Filters
        if ($PSBoundParameters.ContainsKey('AllowedEnvironments')) {
            Write-Debug "$($MyInvocation.MyCommand)|process|filter AllowedEnvironments: $AllowedEnvironments"
            $ReturnObjects = Foreach ($Environment in $AllowedEnvironments) {
                $ReturnObjects | Where-Object AllowedEnvironments -Contains $Environment
            }
        }
        return $ReturnObjects | Sort-Object -Unique Id | Sort-Object Name
    }
}