Custom PSobject HTML output

Welcome Forums General PowerShell Q&A Custom PSobject HTML output

This topic contains 1 reply, has 2 voices, and was last updated by

 
Participant
1 month ago.

  • Author
    Posts
  • #111877

    Participant
    Points: 0
    Rank: Member

    Hello Team,

    My PS Custom object concept is not very clear. So need your help to understand and fix the issue. I want to create a system report which contains multiple information. Following is an example code. I am holding multiple objects' output in a custom object and trying to convert it in HTML, but the result is not showing as I am expecting. I am expecting what I see in the console by enumerating each property should be in HTML file like that. I am definitely sure that I have some conceptual mistakes. But need your support to rectify those.

    
    $hstbl = @{}
    
    $hstbl.Add('RunningSrvs',(gsv -name [a-b]*|select DisplayName, Status |ft -AutoSize))
    
    $hstbl.Add('RunningProcs',(gps -name [a-f]*|? cpu -gt $null |select Name, CPU |ft -AutoSize))
    
    $obj = New-Object PSCustomObject -Property $hstbl
    
    

    I tried for HTML output,

    
    $obj.RunningSrvs|ConvertTo-Html | Out-File C:\test.html
    
    $obj.RunningProcs|ConvertTo-Html | Out-File C:\test.html -append
    
    

    By doing this, getting some kind of wired HTML output.

    Eagerly waiting for your input, please help...

    Regards,

    Roy.

  • #111895

    Participant
    Points: 0
    Rank: Member
    Get-Service -name [a-b]* | select DisplayName, Status | ConvertTo-Html | Out-File .\Report1.html
    
    '(p)(hr)(p)' | Out-File .\Report1.html -Append # replace brackets with html tag characters that won't show here
    
    Get-Process -name [a-f]* | where cpu | select Name, CPU | ConvertTo-Html | Out-File .\Report1.html -Append
    
    & .\Report1.html
    
    

You must be logged in to reply to this topic.