When the server is ping'd the resulting address is compared to an inventory for purposes of keeping the inventory up to date.
I'm trying to tack on the result as "good" or "bad" in the next corresponding cell over. It sort of works except the result is always "bad" with the workflow I have set up.
The CSV contains the server name and IP address pulled from an excel inventory, and is formatted like this:
name,ipaddress server1,10.1.24.51 server2,10.1.24.52 server3,10.1.24.53 server4,10.1.27.101 server5,10.1.27.102 <--- purposely wrong IP address for testing Current script:
$serverlist = Import-Csv -Path file.csv ForEach ($server in $serverlist) { $thisservername = $server.name $thisserveripaddress = $server.ipaddress $pingdaddress = (Test-Connection -ComputerName $thisservername -Count 1 -ErrorAction SilentlyContinue -Verbose).IPV4Address.IPAddressToString if ($pingdaddress -ne $thisserveripaddress) { #$thisservername + " bad" $serverlist | Select-Object name,ipaddress, @{Name='connection';Expression={'bad'}} | ` Export-Csv -Path file.csv -NoTypeInformation } else { #$thisservername + " good" $serverlist | Select-Object name,ipaddress, @{Name='connection';Expression={'good'}} | ` Export-Csv -Path file.csv -NoTypeInformation } }