1

I'm working on a powershell script where I have to define a certain value for a particular setting that is defined as a parameter. Currently I'm using this:

$json = Get-Content $path -Encoding UTF8 | ConvertFrom-Json

$json.AppSettings.RequiresDocument = $value

And it seems to work like that, however if I try to include the parameter like so:

$json = Get-Content $path -Encoding UTF8 | ConvertFrom-Json

$json.$searchValue = $value

I get the error:

"The property 
'AppSettings.RequiresDocument' cannot be found on this object. Verify that the property exists and can be set."

The property does in fact exist and it's the exact same value as before, but for some reason if I switch it for the parameter, I get this error.

E.T.
  • 367
  • 5
  • 18
  • In short: There is no _built-in_ syntax for nested property access based on a _string value_ containing a property _path_ (e.g. `$prop = 'bar.baz'; $object.$prop` looks for a _single_ property literally named `bar.baz`), but there are workarounds: see [this answer](https://stackoverflow.com/a/51863728/45375) to the linked duplicate. – mklement0 Aug 18 '21 at 18:20

0 Answers0