mailserver, powershell, security,

Status Monitoring

agowa338 agowa338 Mar 24, 2016 · 1 min read
Share this

Here is a code sniped to monitor your servers. In the first example the result is simply written into a CSV-File, but in the second a e-mail is sent.

 Import-Csv -Path ".\IP-List.txt" -Header ComputerName
  | Test-NetConnection | Select-Object ComputerName,PingSucceeded | Export-Csv
  -Path ".\Summary.csv" -Delimiter ";" -NoTypeInformation 
 $isOnline = Import-Csv -Path ".\IP-List.txt" -Header
  ComputerName | Test-NetConnection | Select-Object ComputerName,PingSucceeded |
  Where-Object -Property PingSucceeded -EQ -Value $True $DNSHostName =
  (Get-WmiObject win32_computersystem).DNSHostName; $DNSDomainName =
  (Get-WmiObject win32_computersystem).Domain; $From =
  "PowerShellMonitoring@$DNSHostName+'.'+$DNSDomainName"; $To =
  "edv@$DNSHostName+'.'+$DNSDomainName"; $Subject = "Failure
  $(@($isOnline).Count) Hosts down"; $Body = $($isOnline | Format-Table |
  Out-String); Send-MailMessage -From $From -Subject $Subject -To $To -Body
  $Body; 

agowa338
Written by agowa338