I am attempting to put together a simple script that will check the status of a very large list of servers. in this case we\'ll call it servers.txt. I know with Test-Connect
Powershell 7 and Foreach-Object -Parallel
makes it much simpler now:
Get-Content -path C:\Utilities\servers.txt | ForEach-Object -Parallel {
Test-Connection $_ -Count 1 -TimeoutSeconds 1 -ErrorAction SilentlyContinue -ErrorVariable e
if ($e)
{
[PSCustomObject]@{ Destination = $_; Status = $e.Exception.Message }
}
} | Group-Object Destination | Select-Object Name, @{n = 'Status'; e = { $_.Group.Status } }