Private/Get-SFNestedValue.ps1
|
function Get-SFNestedValue { [CmdletBinding()] param ( [Parameter(Mandatory)] $InputObject, [Parameter(Mandatory)] [string]$Path ) $currentValue = $InputObject foreach ($segment in ($Path -split '/')) { if ($null -eq $currentValue -or [string]::IsNullOrWhiteSpace($segment)) { return $null } if ($currentValue -is [System.Collections.IDictionary]) { if (-not $currentValue.Contains($segment)) { return $null } $currentValue = $currentValue[$segment] continue } $property = $currentValue.PSObject.Properties[$segment] if ($null -eq $property) { return $null } $currentValue = $property.Value } return $currentValue } |