Author Posts

September 1, 2014 at 11:55 pm

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

September 2, 2014 at 6:10 am

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.

September 2, 2014 at 6:49 am

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

September 3, 2014 at 6:51 pm

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.

att
Wallace Lima