# Powershell Array output in HTML

**URL:** <https://forums.powershell.org/t/powershell-array-output-in-html/856>\
**Category:** PowerShell Help\
**Created:** [December 31, 2011, 6:30pm UTC](https://forums.powershell.org/t/powershell-array-output-in-html/856 "2011-12-31T18:30:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![archives](https://avatars.discourse-cdn.com/v4/letter/a/bb73d2/32.png) [@archives](https://forums.powershell.org/u/archives)\
**Post date:** [December 31, 2011, 6:30pm UTC](https://forums.powershell.org/t/powershell-array-output-in-html/856/1 "2011-12-31T18:30:00Z")

</div>

by lhornyak at 2013-04-12 07:15:31

> I am working on a script that will return all groups and members of the groups from a site location into html format. When the report runs, I get the data   
> @{Member Name=User1} @{Member Description=Loss Control Rep} @{GroupType=Security}   
> @{Member Name=User2} @{Member Description=Loss Control Specialist} @{GroupType=Security}   
> @{Member Name=User3} @{Member Description=Loss Control Specialist} @{GroupType=Security} etc .returned in the webspage. I tried using the .split command but it is not working exactly the way I would like. How can I format this output to look better?   
> `Add-Content $report "<tr>"$MName=$GroupInfo|Select ‘Member Name’$MDes=$GroupInfo|Select ‘Member Description’$MGroup=$GroupInfo|Select ‘GroupType’Add-Content $report "<td>$MName</td>"Add-Content $report "<td>$MDes</td>"Add-Content $report "<td>$MGroup</td>"#Add-Content $report "<td>$Member.Description</td>"Add-Content $report "</tr>"`  
>   
> Thanks in advance.

by happysysadm at 2013-04-12 08:05:45

> Hi,  
>   
> I don’t know the content of your $groupinfo, but if it is an array, try the following code:  
>   
> [code2=powershell]# preparing report name and location  
> $reportname = 'report' + ("{0:ddMMyyyy-hhmmSS}" -f (get-date)) + '.html'  
> $reportpath = Join-Path -path 'c:\yourreportfolder' -ChildPath $reportname  
> # preparing table using html head  
> # (this piece is not mine but I have often re-used it, I don't remember where I found it))  
> $head = "\<style\>"  
> $head = $head + "BODY{background-color:peachpuff;}"  
> $head = $head + "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}"  
> $head = $head + "TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:thistle}"  
> $head = $head + "TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:PaleGoldenrod}"  
> $head = $head + "\</style\>"  
> # piping $groupinfo into convert to html then on disk in one line  
> $groupinfo|  
> select 'Member name','Member description','GroupType' |  
> Sort-Object 'Member name' |  
> ConvertTo-Html -Head $head -Body "\<H2\>Members and groups\</H2\>"|  
> Out-File -FilePath $reportpath[/code2]  
>   
> Check the syntax (specifically the properties names) and tell me if this is what you were after.  
> Regards  
> Carlo

by lhornyak at 2013-04-12 12:43:25

> I have a lot of nested loops and I will be pulling in a lot of data from different OUs. When I use the convertto-html it does not have the blank rows between each of the nested groups. Here is my code (much of it borrowed and adapted). Is there a way to add blank rows when you use it with the convertto-html method?  
>   
>   
> `$GroupInfo = ‘’ | Select ‘Group Name’,‘Group Description’,‘Member Name’,‘Member Description’,‘GroupType’#######################################################################REPORT HTML CODE#######################################################################$report="Userreports1.htm"Clear-Content $report Add-Content $report "<html>" Add-Content $report "<head>" Add-Content $report "<meta http-equiv=‘Content-Type’ content=‘text/html; charset=iso-8859-1’>" Add-Content $report ‘<title>User Reports $s</title>’ add-content $report ‘<STYLE TYPE="text/css">’ add-content $report "<!–" add-content $report "td {" add-content $report "font-family: Tahoma;" add-content $report "font-size: 11px;" add-content $report "border-top: 1px solid #999999;" add-content $report "border-right: 1px solid #999999;" add-content $report "border-bottom: 1px solid #999999;" add-content $report "border-left: 1px solid #999999;" add-content $report "padding-top: 0px;" add-content $report "padding-right: 0px;" add-content $report "padding-bottom: 0px;" add-content $report "padding-left: 0px;" add-content $report "}" add-content $report "body {" add-content $report "margin-left: 5px;" add-content $report "margin-top: 5px;" add-content $report "margin-right: 0px;" add-content $report "margin-bottom: 10px;" add-content $report "" add-content $report "table {" add-content $report "border: thin solid #000000;" add-content $report "}" add-content $report "–>" add-content $report "</style>" Add-Content $report "</head>" Add-Content $report "<body>" add-content $report "<table width=‘100%’>" add-content $report "<tr bgcolor=‘#CCCCCC’>" add-content $report "<td colspan=‘7’ height=‘25’ align=‘center’>" add-content $report "<font face=‘tahoma’ color=‘#003399’ size=‘4’><strong>User Group Report $Site</strong></font>" add-content $report "</td>" add-content $report "</tr>" add-content $report "</table>" add-content $report "<table width=‘100%’>" Add-Content $report "<tr bgcolor=#CCCCCC>" Add-Content $report "<td width=‘20%’ align=‘center’>Name</td>" Add-Content $report "<td width=‘20%’ align=‘center’>Description</td>" Add-Content $report "<td width=‘20%’ align=‘center’>Group Type</td>" Add-Content $report "</tr>" #######################################################################################$root = "test.com/locations"$GroupArray= get-qadobject -sizelimit 0 -searchroot $root -type groupAdd-Content $report "<tr bgcolor=#FFF000>"Add-Content $report "<td><Strong><Bold>$OU</Bold></Strong></td>"Add-Content $report "<td></td>"Add-Content $report "<td></td>"Add-Content $report "</tr>"$AllGroups = @()Add-Content $report "<tr bgcolor=#FFF000>"Add-Content $report "<td><Strong><Bold></Bold></Strong></td>"Add-Content $report "<td></td>"Add-Content $report "<td></td>"Add-Content $report "</tr>"foreach ($Location in $GroupArray){ $MyGroups = Get-QADGroup $Location -DontUseDefaultIncludedProperties -IncludedProperties Name,Description,Member,GroupType | select Name,Description,Member,GroupType######################################################################## add-content $report "<tr bgcolor=‘#CCCCCC’>"Add-Content $report "<tr bgcolor=#FFF000>"Add-Content $report "<td><Strong><Bold>$Location</Bold></Strong></td>"Add-Content $report "<td></td>"Add-Content $report "<td></td>"Add-Content $report "</tr>"########################################################################foreach($Group in $MyGroups){ $GroupInfo.‘Group Name’ = $Group.Name $GroupInfo.‘Group Description’ = $Group.Descriptionforeach($Member in $Group.Member){ $User = Get-QADUser $Member -DontUseDefaultIncludedProperties -IncludedProperties Name,Description,GroupType| select Name,Description,GroupType if (!$User) {$User = Get-QADgroup $Member -DontUseDefaultIncludedProperties -IncludedProperties Name,Description,GroupType | select Name,Description,GroupType } $GroupInfo.‘Member Name’ = $User.Name $GroupInfo.‘Member Description’ = $User.Description$GroupInfo.‘GroupType’ = $Group.GroupType$GroupInfo | select ‘Group Name’,‘Group Description’,‘Member Name’,‘Member Description’,‘GroupType’ $AllGroups += $GroupInfo | Select ‘Group Name’,‘Group Description’,‘Member Name’,‘Member Description’,‘GroupType’ ##################################################################################Add-Content $report "<tr>"$MName=$GroupInfo|Select ‘Member Name’$MDes=$GroupInfo|Select ‘Member Description’$MGroup=$GroupInfo|Select ‘GroupType’Add-Content $report "<td>$MName</td>"Add-Content $report "<td>$MDes</td>"Add-Content $report "<td>$MGroup</td>"Add-content $report "</br>"Add-Content $report "</tr>"}}}$AllGroups Invoke-item "userreports1.htm"`

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 9:02pm UTC](https://forums.powershell.org/t/powershell-array-output-in-html/856/2 "2024-05-16T21:02:34Z")

</div>


