jimmylew52
asked on
Powershell script for 2008R2 server to check services
I need a script to take server names from a text file and check them for a service that may not be running. Then email me a list of the server names that the service is not running on.
I had one working in 2003 server but it gives many errors I have not been able to solve in 2008r2.
Here is the mess I have been working with, I am very lost. Can someone get me starte on the right path?
$serviceName = "eT Service";
ForEach($Servername in Get-Content C:\MonitorFolder\eTServers .txt){
#$NameStat = @(Get-ChildItem $ServerName | ? {! $_.PsIsContainer})
$serviceStatus = (get-service "$serviceName" -computername $ServerName).Status;
#if ($serviceStatus -ne "Running") {
# $ServerName | out-file C:\MonitorFolder\eTariffCh ecked.txt -append
#$serviceStatus | out-file C:\MonitorFolder\eTariffCh ecked.txt -append
}#}
$NameStat = @(Get-ChildItem $serviceStatus | ? {! $_.PsIsContainer})
Send-MailMessage -From 'ServiceChecker@systrends. com' -To 'me@company.com' `
-SmtpServer 'smtp.company.com' `
-Subject 'Results of Service Check' `
-Body @"
Restart the service on all the servers that show not running: `n`
Please Check the service and restart if necessary.
$(($NameStat | ConvertTo-HTML) -join "`n")
"@
I had one working in 2003 server but it gives many errors I have not been able to solve in 2008r2.
Here is the mess I have been working with, I am very lost. Can someone get me starte on the right path?
$serviceName = "eT Service";
ForEach($Servername in Get-Content C:\MonitorFolder\eTServers
#$NameStat = @(Get-ChildItem $ServerName | ? {! $_.PsIsContainer})
$serviceStatus = (get-service "$serviceName" -computername $ServerName).Status;
#if ($serviceStatus -ne "Running") {
# $ServerName | out-file C:\MonitorFolder\eTariffCh
#$serviceStatus | out-file C:\MonitorFolder\eTariffCh
}#}
$NameStat = @(Get-ChildItem $serviceStatus | ? {! $_.PsIsContainer})
Send-MailMessage -From 'ServiceChecker@systrends.
-SmtpServer 'smtp.company.com' `
-Subject 'Results of Service Check' `
-Body @"
Restart the service on all the servers that show not running: `n`
Please Check the service and restart if necessary.
$(($NameStat | ConvertTo-HTML) -join "`n")
"@
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
My apoligies, I mage an error in your script. It works flawlessly.
Thank you for your assistance.
Thank you for your assistance.
ASKER
You script is much closer than mine but still not working. I get all of the server names in the list tested but no results for the service checked.
Server1 -
server2 -
server3 -
server4 -