Send multiple outputs to the same HTML file in Powershell

18,005

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

Share:
18,005
Admin
Author by

Admin

Updated on June 25, 2022

Comments

  • Admin
    Admin almost 2 years

    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?

  • Admin
    Admin almost 11 years
    So can I use -Fragment multiple times or just once? Thanks for the help worked great. Will be posting another Q soon if I can't figure it about how to use logic to give an OK or List the services not running and then colour code the response! :)