test-connection cmdlet


hello run command ping servers in ad using test-connection  -computername command have read list of server names in text file using 
test-connection -computername (get-content "c:\users\username\desktop\serverlisting1.txt") | select address,destination,ipv4address,bytes,times | export-csv "c:\users\eorosz\desktop\serverping.csv"
output show results "up" or "down" on export csv file. found script 
$inputfile = "c:\users\username\desktop\serverlisting1.txt"  $outputfile = "c:\users\username\desktop\report.csv"  $servers = get-content $inputfile  $collection = $()  foreach ($server in $servers)  {      #$status = @{ "servername" = $server; "timestamp" = (get-date -f s) }      if (test-connection $server -count 1 -ea 0 -quiet)      {           $status["results"] = "up"      }       else       {           $status["results"] = "down"       }      new-object -typename psobject -property $status -outvariable serverstatus      $collection += $serverstatus  }  $collection | export-csv $outputfile -notypeinformation
companies environment won't let me run script in powershell i'm few command lines me same result.  

''>c:\temp\servers.txt gc c:\temp\computers.txt | foreach {if(-not(test-connection -computername $_ -quiet -count 2)){"$_ down" >>c:\temp\servers.txt}else{ "$_ up" >>c:\temp\servers.txt}  }


thanks azam when see answers please mark answer if helpful..vote helpful.



Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

some help on Event 540

WMI Repository 4GB limit - Win 2003 Ent Question

Event ID 1302 (error 1307) DFS replication service encountered an error while writing to the debug log file