question

RisingFlight-7863 avatar image
1 Vote"
RisingFlight-7863 asked KyleXu-MSFT commented

Membership Details

Hi All

i have a requirement to get all the DLs which user is member of. I am using exchange 2016 hybrid environment. When i use the below syntax by connecting to Azure AD, i am getting output. But i want another column to Display Group Type i.e(Distribution, Mail enabled security, Microsoft 365). experts guide me.

 $users = Get-Content -Path "C:\input.csv" 
 ForEach ($user in $users)
 {
 $memberships = Get-AzureADUserMembership -ObjectId $user | Where-Object {$_.MailEnabled -eq $true}
 foreach ($membership in $memberships)
 {
 $membershipDisplayName =  $membership.Displayname
 $membershipMailEnabled = $membership.MailEnabled
 $membershipObjectType = $membership.ObjectType
 $membershipSecurityEnabled = $membership.SecurityEnabled
 $membershipMail = $membership.Mail
 $out = "$user,$membershipDisplayName,$membershipMailEnabled,$membershipObjectType,$membershipSecurityEnabled,$membershipMail"
 $out | Out-File -FilePath C:\temp\output.csv -Append
 }
 }


windows-active-directoryoffice-exchange-online-itpro
· 1
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.

@RisingFlight-7863
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 ·

1 Answer

KyleXu-MSFT avatar image
0 Votes"
KyleXu-MSFT answered

@RisingFlight-7863

You cannot check the group type from Azure AD, if you want to check it, you need to connect to Exchange online at the same time:
Step 1: Connect-AzureAD
Step 2: Connect-ExchangeOnline
Step 3: Run the new script:

  $users = Get-Content -Path "C:\input.csv" 
  ForEach ($user in $users)
  {
  $memberships = Get-AzureADUserMembership -ObjectId $user | Where-Object {$_.MailEnabled -eq $true}
  foreach ($membership in $memberships)
  {
  $membershipDisplayName =  $membership.Displayname
  $membershipMailEnabled = $membership.MailEnabled
  $membershipObjectType = (Get-DistributionGroup $membership.Displayname).GroupType
  $membershipSecurityEnabled = $membership.SecurityEnabled
  $membershipMail = $membership.Mail
  $out = "$user,$membershipDisplayName,$membershipMailEnabled,$membershipObjectType,$membershipSecurityEnabled,$membershipMail"
  $out | Out-File -FilePath C:\temp\output.csv -Append
  }
  }

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.

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.