Hello This is my script
$Computers= gc .\CSV\1.csv foreach ($ComputerName in $Computers) { Try { $DNS =[System.Net.Dns]::GetHostEntry($ComputerName) } Catch { "There was a resolution error: $_ " # Do something in here with your error.... $HostName = "Not in DNS" $IP = "Not in DNS" } $HostName = $DNS.HostName $IP = $DNS.AddressList Trap { Continue } if (Test-Connection $ComputerName -erroraction SilentlyContinue -Count 1 ) { $ComputerName + " ^ " + $Hostname + " ^ " + $IP + " ^ " + "ONLINE" | Out-File -Enc ASCII -Width 400 -Append .\1.txt} else { $ComputerName + " ^ " + $Hostname + " ^ " + $IP + " ^ " + "OFFLINE" |Out-File -Enc ASCII -Width 400 -Append .\1.txt } }
The problem is when a machine can get a Hostname and or IP address it will take the last known Hostname/IP Adress to the next record
PC1234 ^ PC1234.test.nl ^ 192.168.1.24 ^ ONLINE PC2345 ^ PC17786.test.nl ^ 192.168.1.25 ^ OFFLINE PC14238 ^ PC14238.test.nl ^ 192.168.1.26 ^ ONLINE pc1235 ^ PC14238.test.nl ^ 192.168.1.26 ^ OFFLINE pc3587 ^ PC14238.test.nl ^ 192.168.1.26 ^ OFFLINE pc8964 ^ PC14238.test.nl ^ 192.168.1.26 ^ OFFLINE PC17788 ^ PC17788.test.nl ^ 192.168.1.27 ^ ONLINE
PC1235 , PC3587 and PC8964 have the same Computername and ip adress ass PC14238 , but I want to see nothing then instead of this !!
I hope you could help me.
Regards,
Dirk