Ping Log Script


hi guys

i have customer has problems outlook freezing. thought caused exchange server stopped responding. thought might make small script pings destinations , writes output csv file. script not working expected there kind of buffer under-run. thoughts on how optimize script, or if it's possible appreciated :)

[cmdletbinding()]      param(          $hostnames = "dr.dk"      )      begin{          $output = @()          $data = @()          $objects = @()          [int]$counter = 0          foreach ($hostname in $hostnames) { $objects += new-object -typename psobject -property @{"hostname"=$hostname;"ip"=([net.dns]::gethostentry($hostname).addresslist.ipaddresstostring)  }}      }      process{          write-host "press q key stop testing"          while ($true) {              if ($host.ui.rawui.keyavailable -and ("q" -eq $host.ui.rawui.readkey("includekeyup,noecho").character)) {                  write-host "stopping..."                  break              }              write-verbose "defining props"              $props = @{                      "source"=($env:computername);                      "date" = get-date -format d                      "time" = get-date -format t              }              write-verbose "defining object"              $out = new-object -typename psobject -property $props              foreach ($object in $objects) {                  $test = try {test-connection $object.ip -count 1 -erroraction stop| select -expandproperty responsetime } catch  { write-output "failed"}                  add-member -inputobject $out -name $object.hostname -value $test -membertype noteproperty              }              $data += $out              $counter++              start-sleep -seconds 1              if ($counter -eq 60) {                  if (test-path "c:\script\pinglog.csv") {                      $dataold = import-csv "c:\script\pinglog.csv" -delimiter ";"                      $output += $dataold                      $output += $data                       $output | export-csv -path "c:\script\pinglog.csv" -encoding "utf8" -delimiter ";" -notypeinformation                  } else {                      $data | export-csv -path "c:\script\pinglog.csv" -encoding "utf8" -delimiter ";" -notypeinformation                  }                  $counter = 0              }          }      }      end{                    if (test-path "c:\script\pinglog.csv") {              $dataold = import-csv "c:\script\pinglog.csv" -delimiter ";"              $output += $dataold              $output += $data               $output | export-csv -path "c:\script\pinglog.csv" -encoding "utf8" -delimiter ";" -notypeinformation          } else {              $data | export-csv -path "c:\script\pinglog.csv" -encoding "utf8" -delimiter ";" -notypeinformation      }    }  


simple if ask simple question:

test-connection mypc | export-csv myfile.csv -notype


\_(ツ)_/



Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

Edit Group Policy

Hyper-V VM not reaching OS 'Logon' screen

DNS question...