Thursday, March 22, 2018

Find all the Distribution Groups a user is a member of with PowerShell in Office 365

Whether you want to do some reports or debugging, you might need to quickly find out what Distribution Groups a user is a member of! You could go in the user’s profile, see all of the groups , find out which ones are Security, which ones are Distribution Groups.. or you could do an easy PowerShell cmdlet!

Find all the Distribution Groups a user is a member of with PowerShell

Since we will be playing with Exchange Online, you first need to connect to Exchange!

$cred = Get-Credential

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $cred -Authentication Basic -AllowRedirection

Import-PSSession $Session

 

Next up, I will save the Username of the person I am looking for in a variable called Username

$Username = "Jeff.Collins@globomantics.org"

And then, I will use this cmdlet which will get all the Distribution Groups in my tenant, and then find the ones where my username is in the members! (This assumes your e-mail address is the same as the username! If that’s not the case, you can simply put the e-mail in the UserName variable and it will work!)

$DistributionGroups= Get-DistributionGroup | where { (Get-DistributionGroupMember $_.Name | foreach {$_.PrimarySmtpAddress}) -contains "$Username"}

You can now either Display it , or do another action such as removing the user from all of them!

Find all the Distribution Groups a user is a member of with PowerShell in Office 365

That’s it! As you see this is really an quick and easy PowerShell snippet!

 

Leave a comment and don’t forget to like the Absolute SharePoint Blog Page   on Facebook and to follow me on Twitter here  for the latest news and technical articles on SharePoint.  I am also a Pluralsight author, and you can view all the courses I created on my author page.

The post Find all the Distribution Groups a user is a member of with PowerShell in Office 365 appeared first on Absolute SharePoint Blog by Vlad Catrinescu.


by Vlad Catrinescu via Absolute SharePoint Blog by Vlad Catrinescu

No comments:

Post a Comment