Public/Get-specNumberOfItems.ps1

function Get-specNumberOfItems {
    <#
    .SYNOPSIS
    Gets the number of items in a collection.
 
    .DESCRIPTION
    This function calculates the number of items in a given collection. It handles the case where the input collection is null.
 
    .PARAMETER Items
    The collection of items to count.
 
    .RETURNS
    The number of items in the collection, or 0 if the collection is null.
 
    .EXAMPLE
    Get-SpecNumberOfItems -Items @(1, 2, 3)
    Returns 3
 
    .EXAMPLE
    Get-SpecNumberOfItems -Items "hello"
    Returns 1
 
    .EXAMPLE
    Get-SpecNumberOfItems -Items $null
    Returns 0
 
    .NOTES
    Author: owen.heaume
    Version: 1.0.0 - Initial release
    #>

    [cmdletbinding()]

    param (
        $Items
    )

    if ($null -eq $items) {
        return 0
    }

    $count = 0
    $items | % { $count++ }
    return $count
}