question

AustinSundar-2506 avatar image
0 Votes"
AustinSundar-2506 asked AustinSundar-2506 commented

DL Group memberof

i am trying to get "MemberOf" details of each DLs along with the DL report. but it doesn't show any result.
could anyone please help to get the "MemberOf" details?


 Add-PSSnapin microsoft.exchange.management.powershell.snapin
 Set-ADServerSettings -ViewEntireForest $true
 $report = @()
 $Dls = Get-DistributionGroup -Identity ""
 foreach ($dl in $dls)
 {
    $count = (Get-DistributionGroupMember $Dl).Count
    $Members = (get-distributiongroupmember $dl.name | select-object -ExpandProperty name ) -join "`n"
    $acccept1= (Get-DistributionGroup $dl.Name | Select-Object -ExpandProperty AcceptMessagesOnlyFrom) -join "`n"
    $acccept2= (Get-DistributionGroup $dl.Name | Select-Object -ExpandProperty AcceptMessagesOnlyFromDLMembers) -join "`n"
    $acccept3= (Get-DistributionGroup $dl.Name | Select-Object -ExpandProperty AcceptMessagesOnlyFromSendersOrMembers) -join "`n"
    $memberof =Get-ADGroup -Identity $dl.DistinguishedName -Server "" -Properties memberof |select @{n=’MemberOf’; e= { ( $_.memberof | % { (Get-ADObject $_).Name }) -join “,” }} | Sort-Object -Property Name
  
  
     $reportObj = New-Object PSObject
     $reportObj | Add-Member NoteProperty -Name "Name" -Value $Dl.Displayname
     $reportObj | Add-Member NoteProperty -Name "PrimarySmtpAddress" -Value $dl.PrimarySmtpAddress
     $reportObj | Add-Member NoteProperty -Name "OrganizationalUnit" -Value $dl.OrganizationalUnit
     $reportObj | Add-Member NoteProperty -Name "GroupType" -Value $dl.GroupType
     $reportObj | Add-Member NoteProperty -Name "RequireSenderAuthenticationEnabled" -Value $dl.RequireSenderAuthenticationEnabled
     $reportObj | Add-Member NoteProperty -Name "MemberCount" -Value $count
     $reportObj | Add-Member NoteProperty -Name "HiddenFromAddressListsEnabled" -Value $dl.HiddenFromAddressListsEnabled
     $reportObj | Add-Member NoteProperty -Name "ManagedBy" -Value $dl.ManagedBy.name
     $reportObj | Add-Member NoteProperty -Name "DistributionGroupMember" -Value $Members
     $reportObj | Add-Member NoteProperty -Name "AcceptMessagesOnlyFrom" -Value $acccept1
     $reportObj | Add-Member NoteProperty -Name "AcceptMessagesOnlyFromDLMembers" -Value $acccept2
     $reportObj | Add-Member NoteProperty -Name "AcceptMessagesOnlyFromSendersOrMembers" -Value $acccept3
     $reportObj | Add-Member NoteProperty -Name "MemberOf" -Value $memberof
  
  
  
  
        
     $report += $reportObj
  
 }
 $report | Export-Csv
office-exchange-server-administration
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

KyleXu-MSFT avatar image
0 Votes"
KyleXu-MSFT answered AustinSundar-2506 commented

@AustinSundar-2506

Here is it:

 $report = @()
 $Dls = Get-DistributionGroup
 foreach ($dl in $dls) {
     $count = (Get-DistributionGroupMember $Dl).Count
     $Members = (get-distributiongroupmember $dl.name | select-object -ExpandProperty name ) -join "`n"
     $acccept1 = (Get-DistributionGroup $dl.Name | Select-Object -ExpandProperty AcceptMessagesOnlyFrom) -join "`n"
     $acccept2 = (Get-DistributionGroup $dl.Name | Select-Object -ExpandProperty AcceptMessagesOnlyFromDLMembers) -join "`n"
     $acccept3 = (Get-DistributionGroup $dl.Name | Select-Object -ExpandProperty AcceptMessagesOnlyFromSendersOrMembers) -join "`n"
     $memberof = (Get-ADGroup $dl.Name -Properties memberof).MemberOf
      
      
     $reportObj = New-Object PSObject
     $reportObj | Add-Member NoteProperty -Name "Name" -Value $Dl.Displayname
     $reportObj | Add-Member NoteProperty -Name "PrimarySmtpAddress" -Value $dl.PrimarySmtpAddress
     $reportObj | Add-Member NoteProperty -Name "OrganizationalUnit" -Value $dl.OrganizationalUnit
     $reportObj | Add-Member NoteProperty -Name "GroupType" -Value $dl.GroupType
     $reportObj | Add-Member NoteProperty -Name "RequireSenderAuthenticationEnabled" -Value $dl.RequireSenderAuthenticationEnabled
     $reportObj | Add-Member NoteProperty -Name "MemberCount" -Value $count
     $reportObj | Add-Member NoteProperty -Name "HiddenFromAddressListsEnabled" -Value $dl.HiddenFromAddressListsEnabled
     $reportObj | Add-Member NoteProperty -Name "ManagedBy" -Value $dl.ManagedBy.name
     $reportObj | Add-Member NoteProperty -Name "DistributionGroupMember" -Value $Members
     $reportObj | Add-Member NoteProperty -Name "AcceptMessagesOnlyFrom" -Value $acccept1
     $reportObj | Add-Member NoteProperty -Name "AcceptMessagesOnlyFromDLMembers" -Value $acccept2
     $reportObj | Add-Member NoteProperty -Name "AcceptMessagesOnlyFromSendersOrMembers" -Value $acccept3
     $reportObj | Add-Member NoteProperty -Name "MemberOf" -Value $memberof  
            
     $report += $reportObj  
 }
 $report

Here is the result that tested for one distribution group:
76536-qa-kyle-10-26-19.png

You could choose the format that you want:
76480-qa-kyle-10-29-22.png


If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@KyleXu-MSFT
i exported the details to csv and get the error below

![76592-image.png][1]


0 Votes 0 ·
image.png (1.9 KiB)
KyleXu-MSFT avatar image KyleXu-MSFT AustinSundar-2506 ·

Update those two places:

76654-qa-kyle-15-11-56.png


 $memberof = Get-ADGroup $dl.Name -Properties memberof | select @{Expression={$_.MemberOf};Label="value";}
    
 $reportObj | Add-Member NoteProperty -Name "MemberOf" -Value $memberof.value 

0 Votes 0 ·
KyleXu-MSFT avatar image KyleXu-MSFT AustinSundar-2506 ·

@AustinSundar-2506
I am writing here to confirm with you any update about this thread now?
If the above suggestion helps, please be free to mark it as an answer for helping more people.

0 Votes 0 ·

thanks it worked.

0 Votes 0 ·