ps/Modules/Cole.PowerShell.Developer/Public/Get-Coalesce.ps1

28 lines
672 B
PowerShell
Raw Permalink Normal View History

2023-05-30 22:51:22 -07:00
function Get-Coalesce {
<#
.SYNOPSIS
Magic function that returns the first non-null argument passed in
#>
[OutputType([object])]
param (
)
$logLead = (Get-LogLeadName)
if (($args.Length -eq 1) -and ($args -is [System.Collections.IEnumerable] -and $args -isnot [string])) {
$args = $args[0]
}
foreach ($arg in $args) {
if ($null -ne $arg) {
if (($arg -is [string]) -and [string]::IsNullOrWhiteSpace($arg)) {
#skip
} else {
return $arg
}
}
}
Write-Verbose "$logLead : Could not find a non-null value, returning `$null."
return $null
}