2

Suppose I have a foo.exe console app that returns some json, and I want to turn that into a PowerShell object.

I was hoping to simply write:

$o = foo.exe | ConvertFrom-Json

But this doesn't work because the output of the console app is treated as an Array instead of a string. I can instead write:

$o = ([string]foo.exe) | ConvertFrom-Json

which feels dirtier than I was hoping.

Question: can I do better than what I have above to get a PowerShell object out of the output of a console app?

2
  • Your second question would presumably be better asked separately.... Commented Jan 14, 2015 at 6:52
  • @NathanTuggy fair enough, I yanked the second question Commented Jan 14, 2015 at 14:51

1 Answer 1

1

As an option:

$o = foo.exe | Out-String | ConvertFrom-Json
Sign up to request clarification or add additional context in comments.

Comments

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.