Modules/businessdev.ALbuild.Marketplace/Private/ConvertTo-BcResourceList.ps1

function ConvertTo-BcResourceList {
    <#
    .SYNOPSIS
        Normalises a Partner Center / product-ingestion response to an array of resource objects.
 
    .DESCRIPTION
        Ingestion endpoints return either a wrapper object with a '.value' collection or a single
        resource object directly. This unwraps '.value' when present, otherwise wraps the response,
        and always returns an array (use the '@()' idiom at the call site to consume it).
 
        Uses direct `@()` assignment - NOT `$x = if (...) { @(...) } else { @(...) }`. On Windows
        PowerShell 5.1 (the release/build agents) that if-expression form sends the array through the
        output pipeline, which UNWRAPS a single-element array to a scalar. A lone resource then made
        the caller's `.Count` read blank ($null on a scalar PSCustomObject in 5.1), which surfaced as
        the release-309 failure "Unable to locate the product property resource (found )". PS7 masks it
        because a scalar there still answers `.Count = 1`. Keep this in the two-statement form.
    #>

    [CmdletBinding()]
    [OutputType([object[]])]
    param(
        [Parameter(Mandatory, Position = 0)] $Response
    )
    Set-StrictMode -Off
    $list = @($Response)
    if ($Response.value) { $list = @($Response.value) }
    # Emit the array (callers MUST re-wrap with @(): a single-element result unrolls to a scalar on the
    # pipeline, and @() at the call site restores it to a 1-element array so `.Count` is reliable on 5.1).
    return $list
}