Chyba nie można po prostu to zrobić:przekazywać argumenty do scriptblock PowerShell
$servicePath = $args[0]
if(Test-Path -path $servicePath) <-- does not throw in here
$block = {
write-host $servicePath -foreground "magenta"
if((Test-Path -path $servicePath)) { <-- throws here.
dowork
}
}
Więc jak mogę przekazać moje zmienne do scriptblock $ bloku?
Co zrobisz ze swoim blokadą skryptu? Użyj Invoke-Command lub &? –
Jeśli masz zamiar użyć '&', możesz to zrobić: '& {param ($ hello) $ hello} -hello world' – JohnL
@LarsTruijens - Planuję wykonać Invoke-Command-Session – dexter