Functions/ConvertTo-Array.ps1

<#
.SYNOPSIS
    This function converts a wide range of input objects into array objects.
#>

function ConvertTo-Array {
    [CmdletBinding(PositionalBinding=$true)]
    param (
        [Parameter(Mandatory=$true)]
        [AllowNull()]
        $value
    )

    # Null value
    if ($null -eq $value) {
        return ,@()
    }

    # Type is *[]
    elseif ($value.GetType().Name.endsWith("[]")) {
        # More than one value
        if ($value.length -gt 1) {
            return $value | ForEach-Object -Process { $_ }
        }

        # Exactly one value
        elseif ($value.length -eq 1) {
            return ,@($value[0])
        }

        # Empty array
        else {
            return ,@()
        }
    }

    # Type is List`1
    elseif ($value.GetType().Name -eq "List``1") {
        # More than one value
        if ($value.count -gt 1) {
            return $value | ForEach-Object -Process { $_ }
        }

        # Exactly one value
        elseif ($value.count -eq 1) {
            return ,@($value[0])
        }

        # Empty array
        else {
            return ,@()
        }
    }

    # Type is any other object
    else {
        return ,@($value)
    }
}