-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPingAndEmailMe.ps1
More file actions
46 lines (43 loc) · 1.41 KB
/
Copy pathPingAndEmailMe.ps1
File metadata and controls
46 lines (43 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# The Unlicense
# January 2020
# b3b0
# https://github.com/b3b0/checkPatch
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
$ErrorActionPreference = "SilentlyContinue"
function emailMe($aliveComputer)
{
$eventime = Get-Date
$EmailFrom = "ComputerIsAlive@yourdomain.com"
$EmailTo = "you@yourdomain.com"
$Subject ="$aliveComputer is pingable RIGHT NOW!"
$Body = "We thought we lost him forever!"
$SMTPServer = "yoursmtpserverorrleay.yourdomain.com"
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 25)
#$SMTPClient.EnableSsl = $false or $true
$SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)
}
$running = 1
while ($running -eq 1)
{
Write-Host "Starting up!" -ForegroundColor Yellow
foreach ($server in (Get-Content C:\path\to\your\PingAndEmailMeList.txt))
{
Write-Host "Trying $server"
if (Test-Connection -Quiet -ComputerName $server -Count 3)
{
$truly = 0
Write-Host "$server is ALIVE from a network perspective!" -ForegroundColor Green
emailMe($server)
}
if (-not(Test-Connection -Quiet -ComputerName $server -Count 3))
{
Write-Host "$server is DEAD" -ForegroundColor Red
}
}
Write-Host ""
Write-Host "Waiting 10 minutes to try again. Goodnight." -ForegroundColor Blue
Write-Host ""
Get-Date
Write-Host ""
Start-Sleep -Seconds 600
}