In one of my previous posts I wrote about basic configuration steps needed for working with Azure AD via Microsoft Graph Client library (Work with Azure AD via Microsoft Graph API). These steps included registering app within Azure AD and creating authentication provider for authenticating requests with client id and secret from registered app. In this post I will show how to create Azure AD group and set it’s owner programmatically. We will use the same AzureAuthenticationProvider which we used in previous example:
At first we create group (lines 6-15) and add time stamp to the group name (although there may be groups in Azure AD with the same display name, for clearance distinguish them by name). After that we find user by email (lines 17-26) and finally add this user to groups owners (lines 28-34). For convenience I also added here code of AzureAuthenticationProvider from previous example.