powershell - Passing Variables to Start-Job -
i have missing incredibly simple here. here's basic script illustrate i'm trying:
$computers = @('comp1', 'comp2') $scriptblock = { new-item "c:\temp\$c.txt" -force } foreach ($c in $computers) { start-job -scriptblock $scriptblock -argumentlist $c }
the script runs, $c not passed, ".txt" file in folder. simple thing overlooking here?
replace this:
$scriptblock = { new-item "c:\temp\$c.txt" -force }
with this:
$scriptblock = { param($c) new-item "c:\temp\$c.txt" -force }
note: when passing arguments in argumentlist , make sure same number of arguments have accepted inside scriptblock using param.
Comments
Post a Comment