0

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?

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! I was looking for something simple like that

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.