ConvertTo-HTML only writing one row in output file RRS feed

  • Question

  • I have the script running against our ADFS server and I get all of the results in the PS window but when I try to get all of the results to a html file, I only get one row of failed logins. How do I get the results from the PS window to the html? I would love to have the same results from the PS window into the html file. Another issue is that I am not getting the timestamp for the event to show in the html page. Once I get all of the results to show in the html page, I will need to format it so that the results are inside of a table. Any help would be awesome.

    Here is the script that I am running:

    function Write-HTML{ 
          [string]$FilePath = "\\server01\c$\temp\$env:COMPUTERNAME.html",
          [string[]]$Computername = $env:COMPUTERNAME,
    $Css='<style>table{margin:auto; width:98%}
                  Body{background-color:Orange; Text-align:Center;}
                    th{background-color:black; color:white;}
                    td{background-color:Grey; color:Black; Text-align:Center;}
         </style>' )
    Begin{ Write-Verbose "HTML report will be saved $FilePath" }
    Process{ $events = Get-WinEvent -Computername "" @{Logname='Security';Id=1203} |
             Select-Object IpAddresses, ForwardIpAddress, UserId, FailureType, AuditType |
             ConvertTo-Html -Fragment 
    $Report = ConvertTo-Html -Title "$Computername" `
                             -Head "<h1>Account Lockout Report<br><h2><br>This report was ran from the computer name: $Computername</h2><h2><br>This report was created on: $(Get-Date)</h2><br>" `
                             -Body "$TimeStamp $IPaddresses $ForwardedIpAddress $UserId $FailureType $AuditType $Css" }
    End{ $Report | Out-File $Filepath ; Invoke-Expression $FilePath }

    • Edited by InfoCures Thursday, December 5, 2019 1:32 PM Correction in formatting
    Wednesday, December 4, 2019 1:29 PM

All replies

  • Please edit your post and fix it so it is readable and can be copied.


    Wednesday, December 4, 2019 5:17 PM
  • Much appreciated for the knowledge.
    Thursday, December 5, 2019 1:33 PM
  • I suggest adding the help for the CmdLets and searching for articles that will help you understand how to use the CmdLet. You are copying and guessing.

    "Head" is not for HTML display code.  It is for header specific constructs.  For displaying code before the start of the body use "PreContent"

    You don't need two calls to ConvertTo.



    Thursday, December 5, 2019 4:07 PM