We were migrating our classic team sites from on premises to modern team sites. So, the behind the scene Office 365 group for every modern team site.

Our approach is initially creating the empty modern team sites, add owners and then migrate the content. Here we are creating modern team site with our default service account. So, default owner of modern team site and hence of Group is our service account.

Once we added actual owners then we need to remove the default service account. Use-case is removing default service account as a group owner.

Here in this article we will discuss how to remove group owner using Microsoft Graph APIs and CSOM.

Here steps are exactly same as in previous article only change is calling DeleteAsync() of HttpClient class to remove the group owner.

High
Level steps:

Create the instance of HttpClient instance

Set the AccessToken to the request header of HttpClient instance

Rest API to be called for removing owner to the Office 365 Group – https://graph.microsoft.com/v1.0/groups/{groupId}/owners/$ref – {groupId} – Id of the Group for which we need to add the owner

There is method called – DeleteAsync method of HttpClient instance which takes two parameters:

RequestURL – Rest API from step 3

HTTPContent – data to be passed – user id / owner id – Email Id of the user which we need to remove Group owner

Following are the detailed steps with code:Start the Visual Studio 2017, create console application, let’s say “knowledge-junction” as