ConvertTo-HTML Not showing Table

Roel Knippen 6 Reputation points
2021-08-23T13:30:22.103+00:00

Hi

I am having a challenge whit the following script:

$Header = @"  
<style>  
  
    h1 {  
  
        font-family: Arial, Helvetica, sans-serif;  
        color: #000099;  
        font-size: 28px;  
  
    }   
        
    h2 {  
  
        font-family: Arial, Helvetica, sans-serif;  
        color: #000099;  
        font-size: 16px;  
  
    }  
  
      
      
   table {  
		font-size: 12px;  
		border: 0px;   
		font-family: Arial, Helvetica, sans-serif;  
	}   
	  
    td {  
		padding: 4px;  
		margin: 0px;  
		border: 0;  
	}  
	  
    th {  
        background: #395870;  
        background: linear-gradient(#49708f, #293f50);  
        color: #fff;  
        font-size: 11px;  
        text-transform: uppercase;  
        padding: 10px 15px;  
        vertical-align: middle;  
	}  
  
    tbody tr:nth-child(even) {  
        background: #f0f0f2;  
    }  
  
        #CreationDate {  
  
        font-family: Arial, Helvetica, sans-serif;  
        color: #ff3300;  
        font-size: 12px;  
  
    }  
</style>  
  
"@  
  
  
$RaportTitel = "<h1>Rechten </h1>"  
$AanmaakDatum = "<p>Aanmaak Datum: $(Get-Date -format yyyy-MM-dd)</p>"  
$SearchBase = "OU=,OU=,OU=,DC=,DC="  
  
$Groups = Get-ADGroup -Filter * -SearchBase $Searchbase -Properties Name, members  
$Results = foreach( $Group in $Groups ){  
    Get-ADGroupMember -Identity $Group | ForEach-Object {  
         [pscustomobject]@{  
          GroupName = $Group.Name  
          Name = $_.Name  
      }}}  
  
$Results | Select-Object GroupName, Name | ConvertTo-Html -Property GroupName, Name -fragment -PreContent "<h2>test</h2>"  
     
  
$Report = ConvertTo-HTML -Body "$RaportTitel $AanmaakDatum $Results" -Title $RaportTitel -Head $Header  
$Report | Out-File "Pathl"  

When running de script. On the commanline I see that the table is generated. but when I open the report.html I dont''t see the the table.

greetings

Roel Knippen

Windows for business | Windows Server | User experience | PowerShell
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Rich Matheisen 47,901 Reputation points
    2021-08-23T14:40:27.687+00:00

    You haven't stored the output from the "ConvertTo-HTML . . . -fragment" anywhere. You want to use that output in the second ConvertTo-HTML on line #75 in your script.

    This should work:

    $Header = @"
    <style>
        h1 {
    
            font-family: Arial, Helvetica, sans-serif;
            color: #000099;
            font-size: 28px;
        } 
        h2 {
            font-family: Arial, Helvetica, sans-serif;
            color: #000099;
            font-size: 16px;
        }
       table {
            font-size: 12px;
            border: 0px; 
            font-family: Arial, Helvetica, sans-serif;
        } 
        td {
            padding: 4px;
            margin: 0px;
            border: 0;
        }
        th {
            background: #395870;
            background: linear-gradient(#49708f, #293f50);
            color: #fff;
            font-size: 11px;
            text-transform: uppercase;
            padding: 10px 15px;
            vertical-align: middle;
        }
        tbody tr:nth-child(even) {
            background: #f0f0f2;
        }
            #CreationDate {
            font-family: Arial, Helvetica, sans-serif;
            color: #ff3300;
            font-size: 12px;
        }
    </style>
    
    "@
    
    $RaportTitel = "<h1>Rechten </h1>"
    $AanmaakDatum = "<p>Aanmaak Datum: $(Get-Date -format yyyy-MM-dd)</p>"
    $SearchBase = "OU=,OU=,OU=,DC=,DC="
    
    $Results = Get-ADGroup -Filter * -SearchBase $Searchbase -Properties Name, members |
        ForEach-Object {
            $GroupName = $_.Name
            Get-ADGroupMember -Identity $_ | 
                ForEach-Object {
                    [pscustomobject]@{
                        GroupName = $GroupName
                        Name      = $_.Name
                    } 
                }
        }
    $Table = $Results | ConvertTo-Html -Property GroupName, Name -fragment -PreContent "<h2>test</h2>"
    
    $Report = ConvertTo-Html -Body "$RaportTitel $AanmaakDatum $Table" -Title $RaportTitel -Head $Header
    $Report | Out-File "Pathl"
    
    0 comments No comments

  2. Limitless Technology 39,921 Reputation points
    2021-08-26T09:59:27.57+00:00

    Hello Roel K,

    Thank you for your question and reaching out.

    Please follow these steps, it will help you:

    Format-Table creates formatted output that is suitable for displaying it in the console, but not for passing it to ConvertTo-Html.

    Replace Format-Table with Select-Object:

    Get-Website |
    Select-Object @{n='Site_Name';e={$.Name}},
    @{n='Physical Path';e={$
    .physicalpath}},
    @{n='Version';e={($_.physicalpath.split("\"))[-1]}} |
    ConvertTo-Html |
    Out-File -FilePath D:\test.html

    and after that your problem will be resolved.

    If the reply was helpful, please don't forget to upvote or accept as answer.

    Thanks,

    Bharti B

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.