I’ve got a file containing some data in PowerShell Object Notation:
@{ X = 'x'; Y = 'y' }
I’d like to load this into a variable from the file.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
(I figured it out while putting together a repro)
Get-Contentreturns an array with the lines in the file; theOut-Stringis used to join them together.Invoke-Expressionthen runs the script, and the result is captured. This is open to injection attacks, but that’s OK in my specific case.Or, if you prefer your PowerShell terse:
(I can’t find a shorter form of
Out-String)