In my Powershell script, I have an object that I can navigate and get MyProperty value by doing something like:
$x = $obj.Level1.Level2.MyProperty
write-host "MyProperty value is : $($x)"
But, if i change my code as the following, then I am no longer able to get MyProperty value any more:
$mypath= "Level1.Level2"
$x = $obj."$($mypath)".MyProperty
write-host "MyProperty value is : $($x)"
The bottom line is, I need to use variables to navigate the object. I am certain that I must be doing something wrong here, as I am new to Powershell scripting, so please advise - how do I use path in variables to navigate an object?