$members doesn’t reference anything, we need the full script. You’ll have to show us where you are joining the members into a single string. The object only holds one property. Try not scripting inside the psobject, it can be confusing for beginners.
+= is annoying
$results = foreach ($DG in $DistributionGroup){
[PSCustomObject]@{…}}
Using that with only one DG (removing the first two lines of the script and setting $DG), when I type $Results.DGS and $Results.Members it shows what I want… Want to add them all in a single variable to be able to export it…
btw, I was wrong in the |select -first 1 The warning for exchange management shell threw me off course. Seems there has been no development for it since 2007!
|select -first 1 works great in plain PS when enumerating a lot of objects but slower than a prius in EMS.
If I remove the “| Convertto-Html -Fragment -As Table” it shows the names like you formatted them to me “name; name2; name 3; name 4”
In a DG with a lot of members looks awful to read it…
Tried using “$Body+= $item.Members.Split(”;“)” but didn’t worked too…
When I remove the “| Convertto-Html -Fragment -As Table” it returns the DG name and all the members like “name; name1; name2; name3”. It looks awful to read when a DG has a lot of members
Tried to use “$Body+= $item.Members.Split(”;“)” but didn’t worked too…
Using Select -First 1 doesn’t really buy you a lot using it like that. You are still getting ALL of the Distribution Groups and then selecting the first 1. You should always filter as far left as possible, so using the -Filter or -Identity to select a smaller resultset to test your code. I use Select -First, but I’ll normally pull a large resultset once, keep it in memory and then remark it out, so something like this:
When I remove the “| Convertto-Html -Fragment -As Table” it returns the DG name and all the members like “name; name1; name2; name3”. It looks awful to read when a DG has a lot of members
Tried to use “$Body+= $item.Members.Split(”;“)” but didn’t worked too…
It sends the e-mail just like we see the $Results on PowerShell.
I wanted to change the mode it is displayed.
foreach ($item in $Results) {
$Body+="$($item.DG)"
$Body+= $item.Members
}
In this way I get the DG DisplayName in bold and bigger size than regular.
Then I get the members, but they are all in on line. I wanted one line for each member…