 foreach ($UserGroup in $AllGroups){ $GroupName = (Get-ADGroup -Identity $UserGroup).SamAccountName $AllGroupsName += $GroupName } $AllGroupsNameJoined = $AllGroupsName -join ' , ' $EmailTemp = @" <tr> <td class="colorm">$UserName</td> <td>$AllGroupsNameJoined</td> </tr> "@ $EmailResult = $EmailResult + "`r`n" + $EmailTemp 