Gather information of distribution groups and format them to show in HTML


Tried to add that to the $Body variable and the mail sent was a mess =/

$body = $results |select -first 2 | ConvertTo-Html -head $a -body "$item.DG lessthanBRgreaterthan" | out-string

Actually I feel ashamed of asking that kind of things here… Someone may tell me: “search for the solution, stop asking”
I’ll try to read more about PowerShell HTML formatting… Don’t get it why it throws that numbers on the table…

select first one. did you properly add the html breaks?


Here are some prints…
First one - code
Second one - mail received

copy the header html stuff from here, halfway down the page.


Using like this:

$results |select -first 2 | ConvertTo-Html -head $a | Out-File D:\Temp\Test.html

I was able to get it inside a table with the headers (DG and Members) and the data correctly filled.
I think that the problem of not getting the members on each separated line is the type of the variable $Results.Members inside the PSCustomObject… Will try to not set it as [string].

[Update] Tried that… Removing this line:

$String = $Members -join "; "

When I try to convert it to HTML, it shows an * for the DG field and a number for the members field.
When I try to convert each single line to string, it returns “System.Object

I was looking for a PowerShell HTML output with multiple lines value and didn’t find any…
I suppose that it isn’t supported then, maybe that’s why it throws that numbers instead =/

What you are trying to do or what I think you are trying to do doesn’t make sense. If you want the name of the group and then the members on a second line it doesn’t make sense to even create a table in the first place nor convert it to html.

$services = get-service | ConvertTo-Html -Body Listofservices
$services | out-file services.html


Here is what I wanted:

I was trying HTML but if it can be made using another type of file, that’s ok…

The format you are asking for is possible in HTML, you can use nested tables. I used the code posted last time and took the results and sent it to a function to build a report. This example is dumping it to an HTML file (you’ll need to update the path) and will open it in your default browser so you can see what the rendered HTML looks like. Keep in mind if you are sending this as an email, you may need to adjust and use inline CSS to get it to render the same as a browser.

Rob Simmers,

Sorry for taking so long to reply. I was busy with another thing at work…
I’ve tried like this:

$DistributionGroup = Get-DistributionGroup -ResultSize Unlimited | sort DisplayName

$DistributionGroup = $DistributionGroup | select -First 2

$Results = foreach ($DG in $DistributionGroup) {
	$Members = Get-DistributionGroupMember $DG.DisplayName | ForEach-Object{
		if ($_.RecipientType -like "*MailContact*") { $_.Name } else { $_.DisplayName }
	$String = $Members -join "; "
			DistributionGroup = $DG.DisplayName
            Members = $String



#It didn't fit =/

$htmlReport = Out-MyReport -obj $results
$htmlReport | Out-File "C:\Reports\Testreport.html"
ii "C:\Reports\Testreport.html"

The results were this:


I got this working using a tip from Dan Potter (don’t know if this is the best way of doing it…).
I will sent as an image because the forum removes the HTML code part.

The $css code I’ve got from this EqualLogic report: Equallogic Configuration Reporting Powershell Script « Virtualised Reality

Thanks for Dan Potter and Rob Simmers for your time and attention!