Membership Details

Rising Flight 4,216 Reputation points
2021-08-16T05:38:55.33+00:00

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
}
}
Active Directory
Active Directory
A set of directory-based technologies included in Windows Server.
6,245 questions
Microsoft Exchange Online Management
Microsoft Exchange Online Management
Microsoft Exchange Online: A Microsoft email and calendaring hosted service.Management: The act or process of organizing, handling, directing or controlling something.
4,388 questions
{count} vote

Accepted answer
  1. KyleXu-MSFT 26,246 Reputation points
    2021-08-17T02:25:46.003+00:00

    @Rising Flight

    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.

    0 comments No comments

0 additional answers

Sort by: Most helpful