使用此脚本以在 1 个或多个服务未运行时获取电子邮件通知。
这里出了点问题,它发送: System.ServiceProcess.ServiceController 正在运行
$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
如果您的问题是,为什么它返回
system.something
而不是您的服务名称,那是因为$service
不仅仅是服务的名称,而是服务的全部信息,这就是它返回System.ServiceProcess.ServiceController
insted of的原因VSS
。参考服务名称: