Skip to content

Instantly share code, notes, and snippets.

@aflyen
Last active March 8, 2022 08:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aflyen/b9870fe774ab0ef21af9060411d2d763 to your computer and use it in GitHub Desktop.
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
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