-1

I am looking for a PowerShell script to get a export Distribution Group with following Information.

Group Display Name
Group Owner
Group Member
Last Activity Date
Member Count 
Received Email Count
Group ID

I am working on a script but it is returning error

$groupmembers = foreach ($i in Get-DistributionGroup)
 {

    Get-DistributionGroupMember $i | select Display Name, @{n='Member';e={$i.DisplayName}}

}
Theo
  • 57,719
  • 8
  • 24
  • 41
  • Please format you code correctly and share the complete error ... formatted as code as well. – Olaf Jan 21 '23 at 00:17
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Jan 21 '23 at 03:46
  • This time I have edited the question for you, but please read how to [format](https://stackoverflow.com/help/formatting) so you can do this yourself next time. Then of course, please respond to the above comments and add your error message in full because _but it is returning error_ doesn't mean anything. – Theo Jan 21 '23 at 11:59

1 Answers1

0

Get-DistributionGroupMember returns an object of type ReducedRecipient which does not contain a fields called Display or Name - but it does contain a field called DisplayName - i think this is probably your issue.

If you dont want to read the docs, an easy way of seeing the members of an object is to use ConvertTo-Json. Temporarily add the line Get-DistributionGroupMember $i | ConvertTo-Json inside your foreach loop above the command that is failing. It will output the entire ReducedRecipient Object in JSON format so you can easily read the available property names and their current values.

MisterSmith
  • 2,884
  • 1
  • 10
  • 13