我有一个自托管的PowerShell环境,并且有以下脚本
$one = 10
$two = "The value of one is $one"
当我在PowerShell ISE中运行此代码段时,结果与预期的一样
The value of one is 10
当我在自托管的PowerShell环境中运行此字符串时,该字符串未实现,结果保持不变。有人知道如何调用标准行为吗?
最好的问候, zimmy
完整示例
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'