Get-DynamicPath.psm1

$FunctionScriptName = "Get-DynamicPath"
Write-Verbose "Import-Start| [$($FunctionScriptName)]"

function Get-DynamicPath {
    <#
        .SYNOPSIS
        Uses the configured path in Config file to lookup nested PSObject value
    #>

    [cmdletbinding()]
    Param(
        [Parameter()]$Object,
        [Parameter()]$Filter
    )
    Process {
        #* Well formated name - Check dynamic path
        
        if ($Filter -like "*.*") {
            #? Nested path
            $SplitPath = $Filter.split(".")
            if ($SplitPath.count -gt 1) {
                #? Only run if layered path detected
                $SplitIncr = 0
                $nameObject = $Object
                while ($SplitIncr -lt ($SplitPath.count)) {
                    # Run through all layers
                    $nameObject = $nameObject.($SplitPath[$SplitIncr])
                    $SplitIncr++
                }
                #set name
                return $nameObject
        
            } else {
                #? Invalid entry - Trying default
                return $Object.$Filter
            }
        } else {
            #? Simple path
            return $Object.$Filter
        }
    }
}

Export-ModuleMember -Function *
Write-Verbose "Import-END| [$($FunctionScriptName)]"