Я написал сценарий PowerShell, который отправляет оповещение по электронной почте, когда состояние службы зависло или остановлено, но когда я запускаю сценарий в PowerShell в режиме администратора, сценарий по-прежнему показывает, что он работает, но не выдает никакой ошибки или вывода, пожалуйстапомогите мне решить эту проблему.
Я пытался в ОС Windows 10, но не получил ответ от файла сценария.
#AUTHOR: Kevin Olson
#DATE: 4/29/2011
#Machine to be monitored
$Computer = "IN-LINGARCR-1"
#Create an array of all services running
$GetService = get-service -ComputerName $Computer
#Create a subset of the previous array for services you want to monitor
$ServiceArray = "RemoteRegistry"
#Find any iWFM service that is stopped
foreach ($Service in $GetService)
{
foreach ($srv in $ServiceArray)
{
if ($Service.name -eq $srv)
{
#check if a service is hung
if ($Service.status -eq "StopPending")
{
#email to notify if a service is down
Send-Mailmessage -to lckreddy456@gmail.com -Subject "$srv is hung on $Computer" -from lckreddy456@gmail.com -Body "The $srv service was found hung" -SmtpServer smtp.gmail.com
$servicePID = (gwmi win32_Service | where { $_.Name -eq $srv}).ProcessID
Stop-Process $ServicePID
Start-Service -InputObject (get-Service -ComputerName $Computer -Name $srv)
}
# check if a service is stopped '
elseif ($Service.status -eq "Stopped")
{
#email to notify if a service is dow
Send-Mailmessage -to lckreddy456@gmail.com -Subject "$srv is stopped on $Computer" -from lckreddy456@gmail.com -Body "The $srv service was found stopped" -SmtpServer smtp.gmail.com
#automatically restart the service.
Start-Service -InputObject (get-Service -ComputerName $Computer -Name $srv)
}
}
}
}```
Powershell script needs to send an email alert when the service stops or hangs.
Thanks in Advance.