Array html and skip line

matteu31 502 Reputation points
2021-07-27T14:33:53.24+00:00

Hello,

I don't know if what I would like to do can be done.

I use this sample to illustrate

$days= "monday","tuesday","wednesday"  
$result = foreach ($a in 1..4)  
{  
    [pscustomobject]@{  
        Day = $a  
        ScheduleDay = $days -join "`r`n"  
    }  
}  
  
$result | ConvertTo-Html | Out-File "c:\test.html"  
c:\test.html  

I would like to have the result in the next picture.

118304-2021-07-27-16h32-01.png

But my result is this one :

118375-2021-07-27-16h33-13.png

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

Accepted answer
  1. Andreas Baumgarten 123.4K Reputation points MVP Volunteer Moderator
    2021-07-27T15:27:53.91+00:00

    Hi @matteu31 ,

    please try this:

    $days = "monday", "tuesday", "wednesday"  
    $result = foreach ($a in 1..4) {  
        [pscustomobject]@{  
            Day         = $a  
            ScheduleDay = $days -join "::"  
        }  
    }  
    $html = $result | ConvertTo-Html  
    $html.Replace('::', '<br>') | Out-File "c:\temp\test.html"  
    c:\temp\test.html  
    

    Result looks like this here:

    118364-image.png

    ----------

    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards
    Andreas Baumgarten

    0 comments No comments

5 additional answers

Sort by: Most helpful
  1. matteu31 502 Reputation points
    2021-07-27T19:26:26.737+00:00

    Yes, thank you.

    I just asked for what I need help but if you can give me some advices, I would appreciate.
    this is how I built my script (I didn't write all because it's 2600 lines )

    I make function and create custom object and then build my html file.

    function Get-veeamSQLInventory  
    {  
        Write-host "VeeamSQLInventory"  
        $SQLSettings = (Get-ItemProperty "HKLM:\SOFTWARE\Veeam\Veeam Backup and Replication")  
        $instance = (get-itemproperty 'HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server').InstalledInstances  
        $RegistryKey = (Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL').$instance  
        $Edition = (Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\$RegistryKey\Setup").Edition.split(" ")[0]  
        [PScustomObject]@{  
            SQLServerName = $SQLSettings.SqlServerName  
            SQLEdition = $Edition  
            SQLInstanceName = $SQLSettings.SqlInstanceName  
            SQLDatabaseName = $SQLSettings.SqlDatabaseName  
            SQLServiceAccount = (Get-WmiObject win32_service -ComputerName $SQLSettings.SqlServerName -Filter {name like "%mssql%"}).startname  
        }  
        Write-host "-------------------"  
    }  
      
         
    function Get-VeeamRBAC  
    {  
        Write-host "RBAC"  
      
        $RBACreq = Get-VBRUserRoleAssignment  
        foreach ($item in $RBACreq)  
        {  
            [pscustomobject]@{  
                Name = $item.name  
                Type = $item.type  
                Role = $item.role  
            }  
        }  
        Write-host "-------------------"  
    }  
      
    function Get-VeeamConfigurationBackup  
    {  
        Write-host "Configuration Backup"  
      
        $ConfigurationBackupReq = Get-VBRConfigurationBackupJob  
        [pscustomobject]@{  
            Enabled = $ConfigurationBackupReq.Enabled  
            Repository = $ConfigurationBackupReq.Target  
            ScheduleOptions = $ConfigurationBackupReq.ScheduleOptions  
            RestorePointsToKeep = $ConfigurationBackupReq.RestorePointsToKeep  
            EncryptionOptions = $ConfigurationBackupReq.EncryptionOptions  
            LastResult = $ConfigurationBackupReq.LastResult  
        }  
        Write-host "-------------------"  
    }  
      
      
    #HTML Building  
    #Write here all function that need to be displayed in all reports types  
    $VeeamSQLInventory = Get-VeeamSQLInventory  
    $VeeamRBAC = Get-VeeamRBAC  
    $VeeamConfigurationBackup = Get-VeeamConfigurationBackup  
      
    #Function to create Array for HTML  
    Function CreateArray ($title,$var)  
    {  
        "<h3>$title</h3>"  
        $var | ConvertTo-Html -Fragment  
    }  
      
    #region HTML  
    @"  
    <!DOCTYPE html>  
    <html>  
    <head>  
    <style>  
    table {  
       # border-collapse: collapse;  
       border-width: 1px; border-style: solid; border-color: black; border-collapse: collapse;  
    }  
    h2 {text-align:center}  
    th, td {  
        #padding: 8px;  
        #text-align: left;  
        #border-bottom: 1px solid #ddd;  
        border-width: 1px; padding: 3px; border-style: solid; border-color: black;  
    }  
      
    tr:hover{background-color:#f5f5f5}  
    </style>  
    </head>  
    <body>  
    <h1>VEEAM Report</h1>  
      
    $(CreateArray -title VeeamSQLInventory -var $VeeamSQLInventory)  
    $(CreateArray -title VeeamRBAC -var $VeeamRBAC)  
    $(CreateArray -title VeeamConfigurationBackup -var $VeeamConfigurationBackup)  
      
    </body>  
    "@ | Out-File -Encoding utf8 $htmlReportPath  
    #endregion  
      
    Invoke-Item $htmlReportPath  
    
    
     
      
    

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.