How to get child object from PSObject using dot notation string

Question:

providing I have the following JSON

I need to be able to update a value using dotted notation.

The problem I’m getting is that the property cannot be found.

Exception setting “address.streetAddress”: “The property ‘address.streetAddress’ cannot be found on this object. Verify that the property exists and can be set.”

What do I need to do to be able to pass in dotted notation, and update the appropriate value?

Answer:

While you can put a single property name in a variable and use that to access the property, you can’t do that for multiple, dotted properties. You can work around this by using Invoke-Expression:

Source:

How to get child object from PSObject using dot notation string by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply