-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServiceUpdate.ps1
More file actions
34 lines (25 loc) · 1.19 KB
/
ServiceUpdate.ps1
File metadata and controls
34 lines (25 loc) · 1.19 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
$ComputerName = (Get-WmiObject Win32_Computersystem).name
$ServiceName = $args[0]
$ServiceDisplayName = (Get-Service $ServiceName).DisplayName
$TimesRestarted = $args[1]
$Status = (Get-Service $ServiceName).Status
if ($Status -ne "Running")
{
Start-Service $ServiceName
}
function SendAlert
{
$FromAddress = "HostedServiceFailure@xanatek.com"
$ToAddress = "scott@xanatek.com"
$MessageSubject = "Hosted Service Failure for $ComputerName"
$MessageBody = "The $ServiceDisplayName ($ServiceName) service on $ComputerName has restarted $TimesRestarted times in the last 24 hours, please investigate immediately."
$SendingServer = "mail.xanatek.net"
$EmailUsername = "HostedServiceFailure"
$encrypted = Get-Content "C:\ims\email.txt" | ConvertTo-SecureString
$EmailCredential = New-Object System.Management.Automation.PSCredential($EmailUsername, $encrypted)
$SMTPMessage = New-Object System.Net.Mail.MailMessage $FromAddress, $ToAddress, $MessageSubject, $MessageBody
$SMTPClient = New-Object System.Net.Mail.SmtpClient $SendingServer
$SMTPClient.Credentials = $EmailCredential
$SMTPClient.Send($SMTPMessage)
}
SendAlert