Good morning friends
How could I extract the information as follow:
Scenario: Verify a windows service in a list of servers, start this service (if stopped) and send a email with a html table, where listed ok servers, restarted servers and offline servers.
Filter the services and restart its already ok, I don´t know how extract data to build a report.
sorry for misspelling and thank you for attention
great forum! congrats from Brasil
$server = Get-Content c:\temp\server.txt
foreach ($s in $server) {
$service = Get-Service -Name SomeService -ComputerName $s -ErrorAction SilentlyContinue
if(Test-Connection -ComputerName $s -Count 1 -quiet)
{
if ( ($service).Status -eq "Running" )
{
{"put ok servers into a variable A"}
}
else
{
$service | where {$_.status -eq 'Stopped'} | Start-Service
{"put restarted servers into a variable B"}
}
}
else
{
"put offline servers into a variable C"
}
}
$body = "put variables A,B,C in html"
Send-MailMessage -To mail1 -From mail2 -Subject "ServiceStatus" -Body "$body" -SmtpServer mailserver -BodyAsHtml