Class GroupsUtility
Class that deals with Azure Active Directory group CRUD operations.
Inheritance
Namespace: PnP.Framework.Graph
Assembly: PnP.Framework.dll
Syntax
public static class GroupsUtility : object
Methods
AddGroupMembers(String, String[], String, Boolean, Int32, Int32, AzureEnvironment)
Adds members to an Azure Active Directory group
Declaration
public static void AddGroupMembers(string groupId, string[] members, string accessToken, bool removeExistingMembers = false, int retryCount = 10, int delay = 500, AzureEnvironment azureEnvironment = default(AzureEnvironment))
Parameters
System. Id of the Azure Active Directory group to add the members to |
System. String array with the UPNs of the users that need to be added as members to the group |
System. The OAuth 2.0 Access Token to use for invoking the Microsoft Graph |
System. If true, all existing members will be removed and only those provided will become members. If false, existing members will remain and the ones provided will be added to the list with existing members. |
System. Number of times to retry the request in case of throttling |
System. Milliseconds to wait before retrying the request. The delay will be increased (doubled) every retry |
Azure Azure environment to use, needed to get the correct Microsoft Graph URL |
AddGroupOwners(String, String[], String, Boolean, Int32, Int32, AzureEnvironment)
Adds owners to an Azure Active Directory group
Declaration
public static void AddGroupOwners(string groupId, string[] owners, string accessToken, bool removeExistingOwners = false, int retryCount = 10, int delay = 500, AzureEnvironment azureEnvironment = default(AzureEnvironment))
Parameters
System. Id of the Azure Active Directory Group to add the owners to |
System. String array with the UPNs of the users that need to be added as owners to the group |
System. The OAuth 2.0 Access Token to use for invoking the Microsoft Graph |
System. If true, all existing owners will be removed and only those provided will become owners. If false, existing owners will remain and the ones provided will be added to the list with existing owners. |
System. Number of times to retry the request in case of throttling |
System. Milliseconds to wait before retrying the request. The delay will be increased (doubled) every retry |
Azure Azure environment to use, needed to get the correct Microsoft Graph URL |
ClearGroupMembers(String, String, Int32, Int32)
Removes all members of an Azure Active Directory group
Declaration
public static void ClearGroupMembers(string groupId, string accessToken, int retryCount = 10, int delay = 500)
Parameters
System. Id of the Azure Active Directory group to remove all the current members of |
System. The OAuth 2.0 Access Token to use for invoking the Microsoft Graph |
System. Number of times to retry the request in case of throttling |
System. Milliseconds to wait before retrying the request. The delay will be increased (doubled) every retry |
ClearGroupOwners(String, String, Int32, Int32)
Removes all owners of an Azure Active Directory group
Declaration
public static void ClearGroupOwners(string groupId, string accessToken, int retryCount = 10, int delay = 500)
Parameters
System. Id of the Azure Active Directory group to remove all the current owners of |
System. The OAuth 2.0 Access Token to use for invoking the Microsoft Graph |
System. Number of times to retry the request in case of throttling |
System. Milliseconds to wait before retrying the request. The delay will be increased (doubled) every retry |
CreateGroup(String, String, String, Boolean, Boolean, String, String[], String[], Int32, Int32, AzureEnvironment)
Creates a new Azure Active Directory Group
Declaration
public static GroupEntity CreateGroup(string displayName, string description, string mailNickname, bool mailEnabled, bool securityEnabled, string accessToken, string[] owners = null, string[] members = null, int retryCount = 10, int delay = 500, AzureEnvironment azureEnvironment = default(AzureEnvironment))
Parameters
System. The Display Name for the Azure Active Directory Group |
System. The Description for the Azure Active Directory Group |
System. The Mail Nickname for the Azure Active Directory Group |
System. Boolean indicating if the group will be mail enabled |
System. Boolean indicating if the group will be security enabled |
System. The OAuth 2.0 Access Token to use for invoking the Microsoft Graph |
System. A list of UPNs for group owners, if any |
System. A list of UPNs for group members, if any |
System. Number of times to retry the request in case of throttling |
System. Milliseconds to wait before retrying the request. The delay will be increased (doubled) every retry |
Azure Azure environment to use, needed to get the correct Microsoft Graph URL |
Returns
Group The just created Azure Active Directory Group |
DeleteGroup(String, String, Int32, Int32, AzureEnvironment)
Deletes an Azure Active Directory Group
Declaration
public static void DeleteGroup(string groupId, string accessToken, int retryCount = 10, int delay = 500, AzureEnvironment azureEnvironment = default(AzureEnvironment))
Parameters
System. The ID of the Azure Active Directory Group |
System. The OAuth 2.0 Access Token to use for invoking the Microsoft Graph |
System. Number of times to retry the request in case of throttling |
System. Milliseconds to wait before retrying the request. The delay will be increased (doubled) every retry |
Azure Azure environment to use, needed to get the correct Microsoft Graph URL |
GetDeletedGroup(String, String, Uri)
Gets one deleted Azure Active Directory group based on its ID
Declaration
public static GroupEntity GetDeletedGroup(string groupId, string accessToken, Uri graphBaseUri = null)
Parameters
System. The ID of the deleted group. |
System. Access token for accessing Microsoft Graph |
Uri
graphBaseUri
The Microsoft Graph URI to use |
Returns
Group The unified group object of the deleted group that matches the provided ID. |
GetGroup(String, String, Int32, Int32, AzureEnvironment)
Get an Azure Active Directory Group by Id
Declaration
public static GroupEntity GetGroup(string groupId, string accessToken, int retryCount = 10, int delay = 500, AzureEnvironment azureEnvironment = default(AzureEnvironment))
Parameters
System. The ID of the Azure Active Directory Group |
System. The OAuth 2.0 Access Token to use for invoking the Microsoft Graph |
System. Number of times to retry the request in case of throttling |
System. Milliseconds to wait before retrying the request. The delay will be increased (doubled) every retry |
Azure Azure environment to use, needed to get the correct Microsoft Graph URL |
Returns
Group Group instance if found |
GetGroupMembers(GroupEntity, String, Int32, Int32, AzureEnvironment)
Returns all the Members of an Azure Active Directory group
Declaration
public static List<GroupUser> GetGroupMembers(GroupEntity group, string accessToken, int retryCount = 10, int delay = 500, AzureEnvironment azureEnvironment = default(AzureEnvironment))
Parameters
Group The Azure Active Directory group to return its members of |
System. The OAuth 2.0 Access Token to use for invoking the Microsoft Graph |
System. Number of times to retry the request in case of throttling |
System. Milliseconds to wait before retrying the request. The delay will be increased (doubled) every retry |
Azure Azure environment to use, needed to get the correct Microsoft Graph URL |
Returns
List<Group Members of an Azure Active Directory group |
GetGroupOwners(GroupEntity, String, Int32, Int32, AzureEnvironment)
Returns all the Owners of an Azure Active Directory group
Declaration
public static List<GroupUser> GetGroupOwners(GroupEntity group, string accessToken, int retryCount = 10, int delay = 500, AzureEnvironment azureEnvironment = default(AzureEnvironment))
Parameters
Group The Azure Active Directory group object |
System. The OAuth 2.0 Access Token to use for invoking the Microsoft Graph |
System. Number of times to retry the request in case of throttling |
System. Milliseconds to wait before retrying the request. The delay will be increased (doubled) every retry |
Azure Azure environment to use, needed to get the correct Microsoft Graph URL |
Returns
List<Group Owners of an Azure Active Directory group |
GetGroups(String, String, String, Int32, Nullable<Int32>, Int32, Int32, Int32, AzureEnvironment)
Returns all the Azure Active Directory Groups in the current Tenant based on a startIndex.
Declaration
public static List<GroupEntity> GetGroups(string accessToken, string displayName = null, string mailNickname = null, int startIndex = 0, int? endIndex = null, int retryCount = 10, int delay = 500, int pageSize = 999, AzureEnvironment azureEnvironment = default(AzureEnvironment))
Parameters
System. The OAuth 2.0 Access Token to use for invoking the Microsoft Graph |
System. The DisplayName of the Azure Active Directory Group. Leave NULL if you do not want to filter by display name. |
System. The MailNickname of the Azure Active Directory Group. Leave NULL if you do not want to filter by mail nickname. |
System. If not specified, method will start with the first group. |
System. If not specified, method will return all groups. |
System. Number of times to retry the request in case of throttling |
System. Milliseconds to wait before retrying the request. The delay will be increased (doubled) every retry |
System. Page size used for the individual requests to Micrsoft Graph. Defaults to 999 which is currently the maximum value. |
Azure Azure environment to use, needed to get the correct Microsoft Graph URL |
Returns
List<Group List of GroupEntity objects |
ListDeletedGroups(String, Uri)
Lists deleted Azure Active Directory groups
Declaration
public static List<GroupEntity> ListDeletedGroups(string accessToken, Uri graphBaseUri = null)
Parameters
System. Access token for accessing Microsoft Graph |
Uri
graphBaseUri
The Microsoft Graph URI to use |
Returns
List<Group A list of Azure Active Directory group objects that have been deleted |
PermanentlyDeleteGroup(String, String, Uri)
Permanently deletes one deleted Azure Active Directory group based on its ID
Declaration
public static void PermanentlyDeleteGroup(string groupId, string accessToken, Uri graphBaseUri = null)
Parameters
System. The ID of the group to permanently delete |
System. Access token for accessing Microsoft Graph |
Uri
graphBaseUri
The Microsoft Graph URI to use |
RemoveGroupMembers(String, String[], String, Int32, Int32, AzureEnvironment)
Removes members from an Azure Active Directory group
Declaration
public static void RemoveGroupMembers(string groupId, string[] members, string accessToken, int retryCount = 10, int delay = 500, AzureEnvironment azureEnvironment = default(AzureEnvironment))
Parameters
System. Id of the Azure Active Directory group to remove the members from |
System. String array with the UPNs of the users that need to be removed as members from the group |
System. The OAuth 2.0 Access Token to use for invoking the Microsoft Graph |
System. Number of times to retry the request in case of throttling |
System. Milliseconds to wait before retrying the request. The delay will be increased (doubled) every retry |
Azure Azure environment to use, needed to get the correct Microsoft Graph URL |
RemoveGroupOwners(String, String[], String, Int32, Int32, AzureEnvironment)
Removes owners from an Azure Active Directory group
Declaration
public static void RemoveGroupOwners(string groupId, string[] owners, string accessToken, int retryCount = 10, int delay = 500, AzureEnvironment azureEnvironment = default(AzureEnvironment))
Parameters
System. Id of the Azure Active Directory group to remove the owners from |
System. String array with the UPNs of the users that need to be removed as owners from the group |
System. The OAuth 2.0 Access Token to use for invoking the Microsoft Graph |
System. Number of times to retry the request in case of throttling |
System. Milliseconds to wait before retrying the request. The delay will be increased (doubled) every retry |
Azure Azure environment to use, needed to get the correct Microsoft Graph URL |
RestoreDeletedGroup(String, String, Uri)
Restores one deleted Azure Active Directory group based on its ID
Declaration
public static void RestoreDeletedGroup(string groupId, string accessToken, Uri graphBaseUri = null)
Parameters
System. The ID of the deleted group |
System. Access token for accessing Microsoft Graph |
Uri
graphBaseUri
The Microsoft Graph URI to use |
SetGroupVisibility(String, String, Nullable<Boolean>, Nullable<Boolean>, AzureEnvironment)
Sets the visibility of an Azure Active Directory Group
Declaration
public static void SetGroupVisibility(string groupId, string accessToken, bool? hideFromAddressLists, bool? hideFromOutlookClients, AzureEnvironment azureEnvironment = default(AzureEnvironment))
Parameters
System. Id of the Azure Active Directory Group to set the visibility state for |
System. The OAuth 2.0 Access Token to use for invoking the Microsoft Graph |
System. True if the group should not be displayed in certain parts of the Outlook UI: the Address Book, address lists for selecting message recipients, and the Browse Groups dialog for searching groups; otherwise, false. Default value is false. |
System. True if the group should not be displayed in Outlook clients, such as Outlook for Windows and Outlook on the web; otherwise, false. Default value is false. |
Azure Defines the Azure Cloud Deployment. This is used to determine the MS Graph EndPoint to call which differs per Azure Cloud deployments. Defaults to Production (graph.microsoft.com). |
UpdateGroup(String, String, Int32, Int32, String, String, String[], String[], Nullable<Boolean>, Nullable<Boolean>, AzureEnvironment)
Updates the Azure Active Directory Group
Declaration
public static bool UpdateGroup(string groupId, string accessToken, int retryCount = 10, int delay = 500, string displayName = null, string description = null, string[] owners = null, string[] members = null, bool? securityEnabled = null, bool? mailEnabled = null, AzureEnvironment azureEnvironment = default(AzureEnvironment))
Parameters
System. The ID of the Azure Active Directory Group |
System. The OAuth 2.0 Access Token to use for invoking the Microsoft Graph |
System. Number of times to retry the request in case of throttling |
System. Milliseconds to wait before retrying the request. The delay will be increased (doubled) every retry |
System. The Display Name for the Azure Active Directory Group |
System. The Description for the Azure Active Directory Group |
System. A list of UPNs for group owners, if any, to be added to the group |
System. A list of UPNs for group members, if any, to be added to the group |
System. Boolean indicating if the group is enabled for setting permissions |
System. Boolean indicating if the group is enabled for distributing mail |
Azure Azure environment to use, needed to get the correct Microsoft Graph URL |
Returns
System. Boolean indicating whether the Azure Active Directory Group has been updated or not |