28 lines
672 B
PowerShell
28 lines
672 B
PowerShell
|
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
|
||
|
}
|