Reputation: 1222
I have a string variable like this:
$a = "{VAR1: 'value1', VAR2: 'value2', VAR3: 'value3'}"
I have found $ExecutionContext.InvokeCommand.ExpandString($variable) to execute string commands
Is there a way in PowerShell to get that string directly as an array?
Upvotes: 0
Views: 76
Reputation: 7340
You can use ConvertFrom-Json for that:
$a = "{VAR1: 'value1', VAR2: 'value2', VAR3: 'value3'}"
$b = ConvertFrom-Json $a
Then you can access like this:
$b.VAR2
Or if you want an array of the values:
$MyArray = (ConvertFrom-Json $a).PSObject.Properties | select -ExpandProperty value
Upvotes: 1