Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # To call from task scheduler:
- # program: powershell
- # args: -File "C:\Task Scheduler\PingAlert.ps1" -server ServerName -subject "Azure VPN Down" -alertees "helpdesk@mhasp.org,admin@itdata.com"
- # command line: powershell -File "C:\Task Scheduler\PingAlert.ps1" -server ServerName -subject "Azure VPN Down" -alertees
- "helpdesk@domain.org,admin@domain.com"
- Param (
- [string] $server = "ServerName",
- [string] $subject = "Test Subject",
- [string] $alertees = "comma delimited emails")
- # Function to send email - function has to be defined before it's called.
- function sendAlertEmail ()
- {
- Param ([string] $message, [string] $subject)
- $user = "italerts@domain.org"
- $pass = ConvertTo-SecureString -String "P2ssw0rd" -AsPlainText -Force
- $cred = New-Object System.Management.Automation.PSCredential $user, $pass
- $mailParam = @{
- To = $alertees
- From = "IT Alerts <italerts@domain.org>"
- Subject = $subject
- Body = $message
- SmtpServer = "smtp.gmail.com"
- Port = 587
- Credential = $cred
- }
- Send-MailMessage @mailParam -UseSsl
- }
- if (Test-Connection $server -Quiet)
- {
- "Passed"
- }
- else
- {
- sendAlertEmail -message "Failed to ping $server from $env:computername" -subject "[IT Alerts] $subject"
- "Email Sent, will pause the script for about an hour."
- Start-Sleep -Seconds 3500
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement