Office 365 - Getting groups a user is an owner/manager of

Search for a command to run...

No comments yet. Be the first to comment.
Recently, I've been updating a bunch of Visual Studio Azure Functions and Blazor projects to .NET 8.0 from 7.0. Most went smoothly but when I came to run the Azure Functions project locally in Visual Studio, I ran into this error: Error: There is no...

Want to track how long you spend in Microsoft Teams meetings or have a request from a user for some stats? Luckily, it's actually quite easy to get the meeting durations for any user in your tenancy. Common scenarios for needing meeting duration Ok,...

One of the most requested features on Microsoft's UserVoice forum was the Support for Dynamic '+' Email Aliases in Office 365. This has been pending since 2017 and Microsoft finally implemented it in September 2020. Woohoo! However, it's not enabled ...

My computer is in the lounge and it tends to be left on for most of the day (especially with WFH in full effect). With 4 monitors hooked up, it actually outputs a decent amount of light and if you're trying to watch a movie on the TV it can be distra...

Do you run a WordPress site? Have you configured it so that its contents are automatically backed up in case of failure/hack/human error? If it's a no, then you better get cracking as it can happen to anyone. Check out how you can automatically backu...

Recently I've been building an SPFx app that allows a user to see what groups they manage and allow them to bulk update the membership via CSV. One of the first hurdles was to get all the groups the user is an owner/manager of. This needed to work with all group types:
For the focus of this post we are only going to look at groups that are homed/managed in the cloud.
* These groups can currently be managed via Outlook Online so this requirement is a nice to have but not a must have.
There are multiple methods of getting this information. However some require background scripts so arn't really suited for realtime frontend apps. The ideal solution would be to use the Microsoft Graph API so lets take a look on how to accomplish this.
For this example we are going to use the Graph Explorer available here.
There is an API method named List ownedObjects, this lists all directory objects that are owned by a user. This should return all groups as well as devices, apps, etc... You could possibly use an OData query to filter out objects that you don't need.
Note - any Exchange related properties like ManagedBy are not currently filterable, so Distribution Groups and Mail enabled security groups are not returned. The current workaround is manage these groups via Outlook Online. Harvard have some great instructions on how to do that.
https://graph.microsoft.com/v1.0/users/{id | userPrincipalName}/ownedObjects
You can use the Exchange PowerShell cmdlets to get all objects a user is an owner of. From the Exchange side this is commonly referred to as ManagedBy. We are going to make use of the Get-Recipient cmdlet.
Get-Recipient -Filter "ManagedBy -eq 'CN={user},OU={tenant}.onmicrosoft.com,OU=Microsoft Exchange Hosted Organizations,DC=EURPR03A001,DC=prod,DC=outlook,DC=com'" -RecipientTypeDetails GroupMailbox, MailUniversalDistributionGroup, MailUniversalSecurityGroup, DynamicDistributionGroup
Note - This will only retrieve the specfied recipient types. Of course plain old Security Groups arn't exposed in Exchange as they have no email address.
Lastly you can use the Azure AD PowerShell 2.0 cmdlets to retrieve owner information. The cmdlet Get-AzureADUserOwnedObject is what we are going to use.
Get-AzureADUserOwnedObject -ObjectId {objectId}
Get-AzureADUser -SearchString {userPrincipalName | emailAddress} | Get-AzureADUserOwnedObject
Not one method returns all the owner information for all group types. We could wait for Microsoft to update the Graph but that could take a while (if ever). In the meantime pick the one that works for you. It may be that you need to use a couple of them to get all the information you require.
Looking further into the future i'm thinking of building a small intermediary service that combines and caches this information. That data is then exposed by an API that apps can query. It may be possible to combine results from both the Graph and EWS api to get all possible management information.