functions/Get-OrElse.ps1

<#
    .NOTES
        TBD
 
    .DESCRIPTION
        TBD
 
    .PARAMETER Value
        TBD
 
    .PARAMETER Default
        TBD
 
    .EXAMPLE
        Get-OrElse
 
        Example usage Get-OrElse
#>

function Get-OrElse {
    [CmdletBinding()]
    Param(
        [Parameter(ValueFromPipeline = $True)]
        [Object]$Value,

        [Parameter(Mandatory = $True)]
        [Object]$Default
        )

    if($null -eq $Value){
        return $Default
    }

    switch($Value.GetType().Name){
        "String"{
            if([string]::IsNullOrEmpty($Value)){
                return $Default
            }
            else{
                return $Value
            }
        }
        "Hashtable" {
            if($Value.count -eq 0){
                return $Default
            } else{
                return $Value
            }
        }
        "Object[]"{
            if($Value.count -eq 0){
                return $Default
            } else{
                return $Value
            }
        }
        Default {
            return $Value
        }
    }
}