Extract Data and put into Variables

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"}
                $service | where {$_.status -eq 'Stopped'} | Start-Service 
                {"put restarted servers into a variable B"} 
     "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

Take a look at our ebook on creating HTML reports in PowerShell (it’s under the Resources menu).

What you’re doing now has a bit of a problem in that you’re outputting “status” information to the pipeline, which is going to make the pipeline difficult to work with. Write-Verbose would be better. But, as the book outlines, the idea is to get whatever data you want and put it into objects - there are examples. Those can be more easily converted to HTML if you want a report in that form.

Here’s an example of how you could begin to build the report.

I get it!

Gentlemen’s, thank you very much, it worked.

Don, I didn’t know about books section, certainly I will check to improve my skills (and check the results with verbose)

Taylor, great example, such smart code, this trick:

$Body +=
to increment the results in line is just great.

Thanks for attention guys you helped me a lot.

Wallace Lima

Glad to help!