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

Dan,

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?

Dan,

Here are some prints…
First one - code
Second one - mail received
http://postimg.org/gallery/26a0fjcxk/

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

https://technet.microsoft.com/en-us/library/ff730936.aspx?f=255&MSPPError=-2147217396

Dan,

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
.\services.html

Dan,

Here is what I wanted:
https://postimg.org/image/mf0ipmczr/

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 "; "
		
		 [PSCustomObject]@{
			DistributionGroup = $DG.DisplayName
            Members = $String
	}


	
}

$Results


#YOUR CODE HERE
#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:

https://postimg.org/image/c9ld9q3w1/

FINALLY!

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.

https://postimg.org/image/4jajlgag1/

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!