private/SelectObjectWithDefault.ps1
function SelectObjectWithDefault { [CmdletBinding()] param( [Parameter(ValueFromPipeline=$true)] [PSObject] $InputObject, [string] $Name, $Value ) process { if ($_ -eq $null) { $Value } elseif ($_ | Get-Member -Name $Name) { $_.$Name } elseif (($_ -is [Hashtable]) -and ($_.Keys -contains $Name)) { $_.$Name } else { $Value } } } |