Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Start-job not working as expected.

$
0
0

I'm writing a script using test-connection on many servers and want to use the start-job so that each instance runs seperate from the other. The following is the code I have, but the variables don't seem to pass into the job? Without the start-job everything works like a charm. Any help is appreciated! :)

$OurSvrs = get-content C:\Scripts\Monitor\Servers07012013.txt
foreach($Server in $OurSvrs)
{
start-job -scriptblock{
$Avg = 0
$PingServer = Test-Connection -count 5 $Server
$PingServer
$Avg = ($PingServer | Measure-Object ResponseTime -average)
$Calc = $Avg.Average
If ($Calc -lt 0.2)
{
$TnD = Get-Date
'Server ' + $Server + ' failed ping at ' + $TnD >> C:\Scripts\Monitor\PingMonitoring.log
}
}
}


Please mark my post as helpful or the answer or better yet.... both! :) Thanks!


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>