Question:
Is there is any way to tell powershell to construct a hashtable from a string that’s formatted using the normal syntax for creating hashtables inline?
For example, is there any way to do something like:
1 2 3 4 5 6 7 8 |
$fooHashString = "@{key='value'} $fooHash = TellPowershellToEvaluateSpecialStringExpressions($fooHashString) $fooHash Name Value ---- ----- key value |
Answer:
Hmm, shortly after posting this I stumbled upon the answer. I just needed to use the “Invoke-Expression” command on the string.
1 2 3 4 5 6 7 8 |
$fooHashString = "@{key='value'}" $fooHash = Invoke-Expression $fooHashString $fooHash Name Value ---- ----- key value |