0

I have a self-hosted PowerShell environment and I have following script

$one = 10
$two = "The value of one is $one"

When I run this snippet within the PowerShell ISE the result is as I expect

The value of one is 10

When I run this within my self hosted PowerShell environment the string isn't realized and the result is unchanged. Does anybody have an idea how to invoke the standard behavior?

Best regards, zimmy

the full example

var script = $@"
            $one = 10
            $two = 'The value is $one'
     ";

var ps = PowerShell.Create();

ps.AddScript(script);
ps.Invoke();

var valueoftwo = ps.Runspace.SessionStateProxy.GetVariable("two");

Assert.Equal("The value is 10", valueoftwo);
// here the value is 'The value is $one'
zimmybln
  • 149
  • 3
  • 12

0 Answers0