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 -notypeinformationcompanies 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
Post a Comment