using System.DirectoryServices.AccountManagement; // Create the context for the PrincipalContext. using (PrincipalContext context = new PrincipalContext(ContextType.Domain)) { // Create a new group and add it to the directory GroupPrincipal newGroup = new GroupPrincipal(context); newGroup.Name = "Managers"; newGroup.Description = "Group for all managers"; newGroup.Save(); }
using Microsoft.Graph; // Create a new group Group group = new Group { DisplayName = "Managers", MailEnabled = false, SecurityEnabled = true, GroupTypes = new string[]{"Unified"} }; // Add the new group to the Graph API await graphClient.Groups .Request() .AddAsync(group);In this example, the `Groups.Request().AddAsync()` method is used to add a new group to the Microsoft Graph API. The `Group` object is created with the desired parameters and the `AddAsync()` method is used to add the group to the API. Package library: Microsoft.Graph.