Like the title says i'm super new in PowerShell and i was trying to get the ping to a list of different IP's and servers at work.
I found this script on here and it kinda gives what i want (i touched a little bit):
$group = @()
foreach ($ip in $Iplist) {
$status = @{ "Servidor" = $ip; "Fecha" = (Get-Date -Format "dd/MM/yyyy HH:mm") }
$pings = Test-Connection $ip
if ($pings) {
$status["AverageResponseTime"] =
($pings | Measure-Object -Property ResponseTime -Average).Average
$status["Estado"] = "OK"
}
else {
$status["Estado"] = "Down"
}
New-Object -TypeName PSObject -Property $status -OutVariable serverStatus
$group += $serverStatus
}
The output to this one is this:
Estado Fecha AverageResponseTime Servidor
------ ----- ------------------- --------
OK 03/09/2021 22:58 5.25 IP 1
OK 03/09/2021 22:58 33.75 IP 2
OK 03/09/2021 22:58 5.5 IP 3
But i wanted to get an output like this:
------ -------- ------------------- --- --- --------
IP1 03/09/2021 22:58 5.25 4ms 6ms OK
IP2 03/09/2021 22:58 33.75 25ms 40ms OK
IP3 03/09/2021 22:58 5.5 4ms 6ms OK
And honestly i dont know how to get it like that. If anyone has any advice/line i'll greatly appreciate it.