Working on this script to get email notification when 1 or more services are not running.
something is wrong here, it sends: System.ServiceProcess.ServiceController is running
$service=Get-Service "VSS"
if ($Service.Status -ne "Running") {
$Body ="$service is not running"
}
else {
$Body = "$service is running "
}
$From = "email"
$To = "emails"
$SMTPServer = "smtp"
$SMTPPort = "587"
$Username = "email"
$Password = "password"
$Body =$body
$Subject = "$computer$ status"
$smtp = New-Object System.Net.Mail.SmtpClient($SMTPServer, $SMTPPort);
$smtp.EnableSSL = $false
$smtp.Credentials = New-Object System.Net.NetworkCredential($Username, $Password);
$smtp.Send($From, $To, $subject, $body);
$computer = $env:computername
if your question is, why it returns
system.something
instead of your service name, it is because$service
is not just the Name of the Service, it's the whole information of the service, that's why it returnsSystem.ServiceProcess.ServiceController
insted ofVSS
. refer to the Service Name: