Powershell Scripting : A Simple (and Free) Network Monitor

Network monitoring software can be very expensive and time-consuming to set up. The script was designed to save both time and money when a simple PING is all that is needed.

The script keeps the database of devices using a simple CSV file.

If a ping is successful, it will display a message in green. If the device is down, a message will be display in red showing the device is down. An email will be sent to the desired email accounts, notifying you that the device is down. The script can be scheduled to run using Task Scheduler. If the script is set to run in Task Scheduler, the script will run silently. This means up and down messages will not be display 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
}
}