Whether you want to do some reports or debugging, you might need to quickly find out what Office 365 Groups a user is a member or Owner of! You could go in the user’s profile, see all the groups, find out which ones are Security, which ones are Distribution Groups, and which ones are Office 365 Groups. or you could do an easy PowerShell cmdlet!
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 E-mail of the person I am looking for in a variable called UserEmail, and use the GetMailbox cmdlet to save the Mailbox object of that user in a variable called Mailbox.
$UserEmail= "Jeff.Collins@globomantics.org" $Mailbox = Get-Mailbox | Where {$_.PrimarySmtpAddress -eq $UserEmail}
After we have this information, we can use the Get-UnifiedGroup PowerShell cmdlet, together with the Get-UnifiedGroupLinks cmdlet to find which groups this user is a member of!
To find all the Office 365 Groups a user is a member of, we would use the following cmdlet:
$Office365GroupsMember = Get-UnifiedGroup | where { (Get-UnifiedGroupLinks $_.Alias -LinkType Members | foreach {$_.name}) -contains $mailbox.Alias}
We then have all those groups stored in a variable, and we can use them as we wish inside PowerShell!
To find all the Office 365 Groups a user is an owner of, we would use the following cmdlet:
$Office365GroupsOwner = Get-UnifiedGroup | where { (Get-UnifiedGroupLinks $_.Alias -LinkType Owners| foreach {$_.name}) -contains $mailbox.Alias}
As you see, the only thing that changed is the -LinkType parameter from Members to Owners! We now also have all those groups stored in a variable to use as we wish in PowerShell!
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 Office 365 Groups a user is a Member of with PowerShell appeared first on Absolute SharePoint Blog by Vlad Catrinescu.
by Vlad Catrinescu via Absolute SharePoint Blog by Vlad Catrinescu
No comments:
Post a Comment