A Better process Block - Handling Two parameters/ParameterSets

All, first post here. For an exercise I wanted to write an API wrapper in Powershell. Below is the first Get function. It basically works but
I’m wondering if there’s a more elegant way to do the process block. Seems like basically duplicate Foreach loops, but I couldn’t figure out
a better way to handle the two different parameters. I thought I could use $PSItem to
refer to the current object in the pipeline but that doesn’t seem to work. any suggestions?
Also, I’m blind and using a screen reader, so please let me know if there are any glaring formatting issues in this post. Thanks.

Function Get-RLCompany {
    [CmdletBinding(DefaultParameterSetName = 'ByID')]
    Param(
        [Parameter(ValueFromPipelineByPropertyName,
            ParameterSetName = 'ByName')]
        [String[]]$Name,
        [Parameter(ValueFromPipelineByPropertyName,
            ParameterSetName = 'ByID')]
        [String[]]$ID
    )
    Begin {
        $Entity = 'companies'
        $Output = [System.Collections.Generic.LIST[Object]]::New()
    }
    Process {

        If ($PSCmdlet.ParameterSetName -eq 'ByID') {
            $ID | ForEach-Object {
                $Response = Invoke-RLRestMethod -Entity $Entity -Query "id=$($_)"
                $Output.Add($Response)
            }
        }
        elseif ($PSCmdlet.ParameterSetName -eq 'ByName') {
            $Name | ForEach-Object {
                $Response = Invoke-RLRestMethod -Entity $Entity -Query "name=$($_)"
                $Output.Add($Response)
            }

        }

    } 
    End {
        $Output | Write-Output
    }
}

Hi, welcome to the forum :wave:

Your post was perfectly formatted.

Have you simplified your example? I don’t think parameter sets are the right feature to use here. Based on your example, I would use ID as an Alias for name:

Function Get-RLCompany {
    [CmdletBinding()]
    Param(
        [Parameter(ValueFromPipelineByPropertyName)]
        [Alias('ID')]
        [String[]]$Name
    )
    Begin {
        $Entity = 'companies'
        $Output = [System.Collections.Generic.LIST[Object]]::New()
    }
    Process {
            $Name | ForEach-Object {
                $Response = Invoke-RLRestMethod -Entity $Entity -Query "name=$($_)"
                $Output.Add($Response)
            }
    } 
    End {
        $Output | Write-Output
    }
}

What is with the collection of data and output at end? That’s anti pipeline

I should explain a little better what I’m trying to do. This Function gets the data for a company. One can query by name of the company or it’s id number, so that’s why I used two parameterSets because name and id don’t represent the same value. The query for the Rest call does not appear to allow multiple values, so if I want to get data for companies with id 1 and 3, I have to do 2 separate Rest calls to get that data. I want to be able to do Get-RLCompany -ID 1,3, and do the same with the company name, e.g. Get-RLCompany -Name 'Acme','BabylonInc','ThirdInc'. This is why I’m gathering the data in $Output from each Rest call–each call is only going to return 1 company’s data. Does that make more sense?