Reputation: 18848
I have data coming from another command output
testCommand
will print something like this
a: 1
b: test
c: an3
I want to grep value of the specific property testCommand | findstr 'a'
, which prints a: 1
.
But I want to extract the value 1
. Couldn't figure out the way! If it doesn't exist print default value default
Upvotes: 0
Views: 100
Reputation: 174515
If you replace the :
in the output with =
, you can pipe it to ConvertFrom-StringData
and get a nice hashtable instead:
$values = testCommand
$ValueTable = $values -replace ": ","=" |ConvertFrom-StringData
$ValueTable["a"] # this will return the value "1"
Upvotes: 1