Private/Set-ObjectTypeName.ps1

function Set-ObjectTypeName {
    <#
    .SYNOPSIS
        Gives the objects returned by the API a type name and returns them.

    .DESCRIPTION
        The API returns plain objects. A type name such as Ghost.Post lets the format files in ObjectDefinitions
        show the most useful properties as a table, while every property stays available.

    .EXAMPLE
        Set-ObjectTypeName -InputObject $result -TypeName $resources.TypeName

        Returns the objects in $result, typed as defined for the endpoint.
    #>

    [CmdletBinding()]
    [OutputType([object])]
    [Diagnostics.CodeAnalysis.SuppressMessageAttribute(
        'PSUseShouldProcessForStateChangingFunctions', '',
        Justification = 'Adds a type name to objects in memory. Nothing is changed on the system or on the site.'
    )]
    param(
        # The objects to give a type name.
        [AllowNull()]
        [AllowEmptyCollection()]
        [object[]] $InputObject,

        # The type name, such as Ghost.Post. Without it the objects are returned unchanged.
        [string] $TypeName
    )

    foreach ($item in $InputObject) {
        if ($null -eq $item) {
            continue
        }

        if ($TypeName) {
            $item.PSObject.TypeNames.Insert(0, $TypeName)
        }
        $item
    }
}