My Powershell code doesn't evaluate the $agent
variable:
foreach ($agent in $agentcomputers) {
Write-Output 'Starting agent on '$agent
# psexc to start the agent
Start-Job -ScriptBlock {& psexec $agent c:grinderexamplesstartAgent.cmd}
}
This link is similar to my problem, except I'm not calling an external Powershell script.
I tried adding that in, using $args[0]
for $agent
, and adding the -ArgumentList
parameters, but that didn't work.
Edits/Replies
$agentcomputers
is just a list of computer names - each on its own line:
$agentcomputers = Get-Content c:grinder-distagent-computers.txt
I have also tried this - and $args[0]
doesn't evaluate:
Start-Job -ScriptBlock {& psexec $args[0] c:grinderexamplesstartAgent.cmd} -ArgumentList @($agent)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…