A Simple (and Free) Network Monitor

Network monitoring software can be very expensive and time-consuming to set up. This script was designed to save both time and money when a simple PING will do.

The database of devices is kept using a simple CSV file.

If a ping is successful, a message will be displayed in green. If the device is down a message will be displayed in red indicating the device is down. Additionally, an email will be sent to the desired email accounts notifying you that the device is down. This script can be scheduled to run using Task Scheduler. If the script is set up to run in Task Scheduler, the script will run silently. This means up and down messages will not be displayed on the console but an email will be sent if a device is down.


Example CSV File

Name,IP
Device1,8.8.8.8
Device2,8.8.4.4
Device3,1.1.1.1
Device4,208.67.222.222
Device5,208.67.220.220

 


 Entire Script

This script is also available on Microsoft TechNet: http://bit.ly/2V5BjCX


####################################################
# ITLUMBERJACK.COM
# UPDATED ON: 5/6/19
# LICENSE: https://www.itlumberjack.com/mit-license
####################################################

#######################################
### CSV File Structure and Location ###
#######################################

<#

Below is the CSV File Structure. 

Name,IP
Device1,8.8.8.8
Device2,8.8.4.4
Device3,1.1.1.1
Device4,208.67.222.222
Device5,208.67.220.220

#>

$Monitored_Devices = import-csv C:\Device-Monitor\Device-Monitor.csv

#####################
### SMTP Settings ###
#####################

$SMTP_Username = "Username"
$SMTP_Password = ConvertTo-SecureString "Password" -AsPlainText -Force
$Creds = New-Object System.Management.Automation.PSCredential ($SMTP_Username, $SMTP_Password)
$From = ""
$To = ""
$SMTPServer = ""
$SMTPPort = ""

##############
### SCRIPT ###
##############

foreach ($Monitored_Device in $Monitored_Devices) {
$DeviceName = $Monitored_Device.Name
$IPAddress = $Monitored_Device.IP

$Ping_Test = Test-Connection -ComputerName $IPAddress -Quiet

if ($Ping_Test -eq $true){ 
Write-Host $CameraName -ForegroundColor Green
}

else {
Write-Host $DeviceName -ForegroundColor Red
$Subject = $DeviceName + " | " + (Get-Date).ToString()
$Body = $DeviceName + " is down. IP Address: " + $IPAddress
Send-MailMessage -From $From -to $To -Subject $Subject -Body $Body -SmtpServer $SMTPServer -port $SMTPPort -UseSsl -Credential $Creds –DeliveryNotificationOption OnSuccess -BodyAsHtml
}
}