Reputation: 36573
Consider the following
$y = 'foo'
$x = {
write-host $y
}
powershell -NoProfile -ExecutionPolicy Bypass -Command "$x"
This will not print foo, but I'd like it to. Is there a way to force powershell to inline these variables?
Upvotes: 1
Views: 229
Reputation: 68273
One option:
$y = 'foo'
$x = [scriptblock]::Create("Write-Host $y")
powershell -NoProfile -ExecutionPolicy Bypass -Command "$x"
Upvotes: 0