question

RoelKnippen-6675 avatar image
0 Votes"
RoelKnippen-6675 asked LimitlessTechnology-2700 answered

ConvertTo-HTML Not showing Table

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-server-powershell
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

RichMatheisen-8856 avatar image
0 Votes"
RichMatheisen-8856 answered RichMatheisen-8856 edited

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"


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

LimitlessTechnology-2700 avatar image
0 Votes"
LimitlessTechnology-2700 answered

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

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.