Avatar of nav2567
nav2567
Flag for United States of America

asked on 

Use PS Script to check computer connection status.

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"
  }
}
PowershellWindows Server 2012

Avatar of undefined
Last Comment
nav2567

8/22/2022 - Mon