Send multiple outputs to the same HTML file in Powershell

user2299515 picture user2299515 · May 14, 2013 · Viewed 17.5k times · Source

Trying to figure out how to convert to HTML multiple service checks:

I have this script:

Get-service -Computername SERVER1 -Name *SERVICE1* | ConvertTo-Html -Body "<H2>Service 1 Check</H2> " -Property Name,Status 
Get-Service  -Computername SERVER2 -name *SERVICE2* | ConvertTo-Html -Body "<br><H2>Service 2 Check</H2> " -Property Name,Status | Out-File  c:\servicecheck.htm

Is this possible?

Answer

Angshuman Agarwal picture Angshuman Agarwal · May 14, 2013

May be you can do something like this -

$Event = Get-EventLog -LogName Security -newest 100 | ConvertTo-HTML -Fragment 
$Process = Get-Process | ConvertTo-HTML -Fragment 
ConvertTo-HTML -Body "$Event $Process" -Title "Status Report" |  Out-File c:\StatusReport.html

NB: Replace $Event and $Process with your service cmdlets.

-Fragment [<SwitchParameter>] Generates only an HTML table. The HTML, HEAD, TITLE, and BODY tags are omitted.

Reference - http://technet.microsoft.com/en-us/magazine/hh127059.aspx