Powershell pass variable to start-job

前端 未结 2 697
闹比i
闹比i 2020-11-28 10:48

within powershell I\'d like to learn the best way to call a variable to a start job so I don\'t have to edit the script for each server as it will be specific based on the c

2条回答
  •  半阙折子戏
    2020-11-28 11:09

    Use the -ArgumentList parameter on Start-Job e.g.:

    Start-Job -Scriptblock {param($p) "`$p is $p"} -Arg 'Server1'
    

    In your case:

    $pingblock = {param($servername) pathping $servername | Out-File C:\...\ServerPing.txt}
    Start-Job $pingblock -Arg Server1
    

提交回复
热议问题