1

考虑以下

$y = 'foo'
$x = {
    write-host $y
}

powershell -NoProfile -ExecutionPolicy Bypass -Command "$x"

这不会打印 foo,但我想要它。有没有办法强制 powershell 内联这些变量?

4

1 回答 1

0

一种选择:

$y = 'foo'
$x = [scriptblock]::Create("Write-Host $y")

powershell -NoProfile -ExecutionPolicy Bypass -Command "$x"
于 2016-04-13T18:17:32.403 回答