Hi
I want to ping multiple hosts from the powershell/CMD and needs to get information like host is UP or Down and host's IP adress.
In case host is down it should still return the IP address of the host.
If host doesnt exist then no worries.
I tried below command but its not returning IP ADDRESS for hosts which are down but EXIST.
$Host
=
Test-Connection
$server
-Count
1
-Quiet
-ErrorAction
SilentlyContinue
$ip
=
Test-Connection
$server
-Count
1 | select ipv4address
-ErrorAction
SilentlyContinue
$ip
=
$ip
.IPV4Address
if
(
$Host
.ToString()
-like
"true"
) {
Write-Host
"$server $ip is pingable"
-ForegroundColor
green
Write-Output
"$server,$ip,yes"
|
Out-File
$OutFile
-Append
}
else
{
Write-Host
"$server not pingable"
-ForegroundColor
Red
Write-Output
"$server,$ip,no"
|
Out-File
$OutFile
-Append
}