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

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -