Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send multiple outputs to the same HTML file in Powershell

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?


1 Answers

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

like image 116
Angshuman Agarwal Avatar answered Dec 10 '25 01:12

Angshuman Agarwal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!