Office 365 Groups for Admins - simple reporting using PowerShell

Tags: Office 365, Unified Groups, PowerShell

In this post, in the Office 365 Groups for Admins series, I will leverage what we learned in the previous posts, combine it with some PowerShell magic and create some basic reports. You can use these reports as a base for your Office 365 Groups reporting in your organization.

Note: all these reports require that you have connected to your Exchange Online tenant with appropriate permissions, see this post about more details.

List all Groups

The most simple and most obvious report is of course to use the Get-UnifiedGroup cmdlet. That one gives you the basic details such as group names, creation dates etc:

Get-UnifiedGroup | Format-Table Alias, PrimarySmtpAddress, WhenCreated, WhenChanged

Simple Group report

Show some more details

Most often you need more details, specifically with the member details. Here's how you can combine the Get-UnifiedGroup cmdlet with the Get-UnifiedGroupLinks cmdlet to show how many members and owners each group have:

Get-UnifiedGroup | 
    select Id,Alias, AccessType, Language,Notes, PrimarySmtpAddress, `
    HiddenFromAddressListsEnabled, WhenCreated, WhenChanged, `
    @{Expression={([array](Get-UnifiedGroupLinks -Identity $_.Id -LinkType Members)).Count }; `
    Label='Members'}, `
    @{Expression={([array](Get-UnifiedGroupLinks -Identity $_.Id -LinkType Owners)).Count }; `
    Label='Owners'} |
    Format-Table Alias, Members, Owners

Another Group report

This command might take a while if you have many Groups and many members. So if want to do some operations on this you should store it in a local variable.

You can also use this result and store it in a file (or upload it to SharePoint) if you would like to compare how your Groups change over time. For this I prefer to use the Export-CliXml and Import-CliXml cmdlets to persist the data as an XML file and then the Compare-Object cmdlet to find differences. You can do something like this to compare Groups from one day to another:

# Get Group data (using the command above)
$allGroups = Get-UnifiedGroup | select ...

# Get previous days Groups
$previousData = Import-Clixml -LiteralPath c:\temp\groups-data.xml

# Compare the results
Compare-Object -ReferenceObject $previousData -DifferenceObject $allGroups `
    -Property Members,Owners -PassThru | `
    Format-Table  Alias, Members, Owners, SideIndicator

# Export the new data
$allGroups | Export-CliXml c:\temp\groups-data.xml 

Comparing Groups

The SideIndicator indicates the changes; => is new stuff and <= is old stuff. In the picture above you can see that the Members and Owners properties of one Group has increased to 3, from 2. And we also have one brand new Group, with 1 member.

Finding users in Groups

Sometimes you need to find out which users are members or owners of certain Groups. Of course you can use Azure AD cmdlets to find memberships but another way is to use a modification of the command above:

$allGroupsObj = Get-UnifiedGroup | 
    select Id,Alias,  `
    @{Expression={Get-UnifiedGroupLinks -Identity $_.Id -LinkType Members | `
    select Name}; Label='Members'}, `
    @{Expression={Get-UnifiedGroupLinks -Identity $_.Id -LinkType Owners | `
    select Name}; Label='Owners'}

This allows you to find out which Groups a specific user is Member and/or Owner of. To find which Groups Katie Jordan is owner of you fire off a command like this:

$allGroupsObj | Where-Object{$_.Owners | Where-Object{ $_.Name -eq 'KatieJ'}} | `
    select Alias

KatiJ is the owner

Summary

I hope this post showed you how you can create reports of your Office 365 Groups, in wait for Microsoft to provide us with better tools. And I hope you actually do reporting on your Groups, since that is an essential part of your Office 365 Governance and your understanding on how your users work.

1 Comment

  • Bryan said

    The snippet under Finding users in Groups is not a very good output, and I haven't been able to figure out how to modify it to get a good, clean output of the groups and their associated members and owners. The output for users looks like, "{@{Name=FLastname}, where I just want to see FLastname

Comments have been disabled for this content.

About Wictor...

Wictor Wilén is the Nordic Digital Workplace Lead working at Avanade. Wictor has achieved the Microsoft Certified Architect (MCA) - SharePoint 2010, Microsoft Certified Solutions Master (MCSM) - SharePoint  and Microsoft Certified Master (MCM) - SharePoint 2010 certifications. He has also been awarded Microsoft Most Valuable Professional (MVP) for seven consecutive years.

And a word from our sponsors...