我有这样的事情:> write-host "this is the body of the script that I want to add to anotherwrite-host "so that I can execute this automatically created script somewhere " }
$scriptBlock
PowerShell ScriptBlock不是,因为它不会关闭其声明环境中引用的变量。相反,它似乎利用了动态作用域和自由变量,这些变量在运行时绑定在lambda表达式中。existed during the evaluation of the bar function在ScriptBlock上调用GetNewClosure()会返回