þÿ<# .SYNOPSIS Pings a file list of systems, and displays the results in a GridView. Generates up to 50 Asynchronous jobs to expedite ping. .DESCRIPTION Pings a file list of systems, and displays the results in a GridView. Generates up to 50 Asynchronous jobs to expedite ping. .NOTES File Name : Get-PingStatusList Author : Greg Ramsey - ramseyg@hotmail.com Requires : PowerShell 2.0 and Microsoft .NET Framework 3.5 .LINK Based on Thomas Lee's Get-PingStatus.ps1: http://pshscripts.blogspot.com Win32_PingStatus: http://msdn.microsoft.com/en-us/library/aa394350(VS.85).aspx .PARAMETER FileName The File that contains the list of systems to ping, one per line. .EXAMPLE .\Get-PingStausList.ps1 .\MyServers.txt Approx 12 Systems for ping check Pinging Computer1 Pinging Computer2 ... .EXAMPLE .\Get-PingStausList.ps1 \\myServer\MyShare\Americas\AmericasServers.txt Approx 387 Systems for ping check Pinging Computer1 Pinging Computer2 ... Pinging Computer49 Pinging Computer50 50 Concurrent jobs running, sleeping 5 seconds 50 Concurrent jobs running, sleeping 5 seconds 50 Concurrent jobs running, sleeping 5 seconds Pinging Comptuer51 ... #> [Cmdletbinding()]param ( [Parameter(Position=0,mandatory=$True)][string] $strFileName) $starttimer = Get-Date #This is total number of jobs that will run at one time. $MaxConcurrentJobs = 50 #verify the file exists if (test-path $strFileName) { $CollSystems = (get-content $strFileName) "Approx {0} Systems for ping check" -f ($CollSystems | Measure-Object).count #now ping each system - multi-threaded, max of $MaxConcurrentJobs at a time. $CollSystems | foreach { if ($_.length -gt 0) { "Pinging {0}" -f $_ start-job -scriptblock {invoke-expression "get-wmiobject -Query `"select * from win32_pingstatus where timeout=3000 and Address='$args'`""} -name("Ping-" + $_) -argumentlist $_ | out-null } while (((get-job | where-object { $_.Name -like "Ping*" -and $_.State -eq "Running" }) | measure).Count -gt $MaxConcurrentJobs) { "{0} Concurrent jobs running, sleeping 5 seconds" -f $MaxConcurrentJobs Start-Sleep -seconds 5 } } #wait for all jobs that start with 'Ping*' to complete... while (((get-job | where-object { $_.Name -like "Ping*" -and $_.state -eq "Running" }) | measure).count -gt 0) { $jobcount = ((get-job | where-object { $_.Name -like "Ping*" -and $_.state -eq "Running" }) | measure).count Write-Host "Waiting for $jobcount Jobs to Complete" Start-Sleep -seconds 5 $Counter++ if ($Counter -gt 40) { Write-Host "Exiting loop $jobCount Jobs did not complete" get-job | where-object { $_.Name -like "Ping*" -and $_.state -eq "Running" } | select Name break } } $PingResults = @( ) #Import all job state into $PingResults Array get-job | where { $_.Name -like "Ping*" -and $_.state -eq "Completed" } | % { $PingResults += Receive-Job $_ ; Remove-Job $_ } $stoptimer = Get-Date #Display info, and display in GridView Write-Host Write-Host "Ping Complete!" "Total time for ping: {0} Minutes" -f [math]::round(($stoptimer - $starttimer).TotalMinutes , 2) "{0} Systems Offline, and did not resolve an IP" -f (($PingResults | where-object {$_.statusCode -eq $Null}) | measure-object ).Count "{0} Systems Offline, and did resolve an IP" -f (($PingResults | where-object {$_.statusCode -eq 11010}) | measure-object ).Count "{0} Systems Online" -f (($PingResults | where-object {$_.statusCode -eq 0}) | measure-object ).Count $PingResults | select Address, IPV4Address, StatusCode | Sort-Object StatusCode | out-gridview } else { "Invalid FilePath!" }