Last active
March 8, 2022 08:41
-
-
Save aflyen/b9870fe774ab0ef21af9060411d2d763 to your computer and use it in GitHub Desktop.
Set the Microsoft 365 group to not be visible in the Global Address List in Exchange with C# and Microsoft Graph SDK. Ref: https://docs.microsoft.com/en-us/graph/api/group-update?view=graph-rest-1.0&tabs=http
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private async Task SetHideFromAddressLists(GraphServiceClient client, string groupId) | |
{ | |
var retry = true; | |
var retryCount = 0; | |
var body = new | |
{ | |
hideFromAddressLists = true | |
}; | |
while (retry) | |
{ | |
try | |
{ | |
var request = new HttpRequestMessage(new HttpMethod("PATCH"), client.Groups[groupId].Request().RequestUrl) | |
{ | |
Content = new StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(body), Encoding.UTF8, "application/json") | |
}; | |
await client.AuthenticationProvider.AuthenticateRequestAsync(request); | |
await client.HttpProvider.SendAsync(request); | |
retry = false; | |
} | |
catch | |
{ | |
await Task.Delay(5000); | |
retryCount++; | |
} | |
if (retryCount > 10) | |
{ | |
retry = false; | |
} | |
} | |
return; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment