i'm using windows server 2003, now i have a script to restart one specific service, can someone guide me how to run this script in parallel? i already use start-job, but seems it only run in backround but still sequential, below is my script:
file name: restart-service.ps1
$start = Get-Date
$Serverlist = Get-Content -path C:\Computers.txt
ForEach ($Server in $Serverlist){
start-job -scriptblock {param($Server) Restart-Service -InputObject $(Get-Service -ComputerName $Server -Name "aspnet_state")} -ArgumentList $Server
}
Get-Job | Wait-Job
Get-Job | Receive-Job
$end = Get-Date
$timespan = $end - $start
$seconds = $timespan.TotalSeconds
Write-Host "This took me $seconds seconds."
or this
$start = Get-Date
$Server = Get-Content -path C:\Computers.txt
$scriptblock = {
Param($Server)
Restart-Service -InputObject $(Get-Service -ComputerName $Server -Name "aspnet_state")
}
$Server | % {Start-Job -Scriptblock $scriptblock -ArgumentList $_ | Out-Null}
Get-Job | Wait-Job | Receive-Job
$end = Get-Date
$timespan = $end - $start
$seconds = $timespan.TotalSeconds
Write-Host "This took me $seconds seconds."
but i only can see the result, but can not see any result related information of my server's IP, can someone help me how to improve it...