Hello,
I have a text file that contains list of computer hostnames.
I am using the below script to check if the host is live. If yes, put UP next to the hostname. Otherwise, put DOWN.
For some reason, it is not working. Please check and advise. Thanks.
import-module activedirectory
$names = Get-content "hnames.txt"
foreach ($name in $names){
if (Test-Connection -ComputerName $name -Count 1 -ErrorAction SilentlyContinue){
Write-Host "$name,up"
}
else{
Write-Host "$name,down"
}
}