Skip to main content

spo group member add

Add members to a SharePoint Group

Usage

m365 spo group member add [options]

Options

-u, --webUrl <webUrl>

URL of the site where the SharePoint group is available.

--groupId [groupId]

Id of the SharePoint Group to which the user needs to be added. Specify either groupId or groupName.

--groupName [groupName]

Name of the SharePoint Group to which the user needs to be added. Specify either groupId or groupName.

--userNames [userNames]

User's UPN (user principal name, eg. megan.bowen@contoso.com). If multiple users need to be added, they have to be comma-separated (e.g. megan.bowen@contoso.com,alex.wilber@contoso.com). Specify either userIds, userNames, emails, aadGroupIds or aadGroupNames.

--emails [emails]

User's email (eg. megan.bowen@contoso.com). If multiple users need to be added, they have to be comma-separated (e.g. megan.bowen@contoso.com,alex.wilber@contoso.com). Specify either userIds, userNames, emails, aadGroupIds or aadGroupNames.

--userIds [userIds]

The user Id of the user to add as a member. (Id of the site user, for example: 14) If multiple users need to be added, the Ids have to be comma-separated. Specify either userIds, userNames, emails, aadGroupIds or aadGroupNames.

--entraGroupIds [entraGroupIds]

The object Id of the Entra group to add as a member. If multiple groups need to be added, the Ids have to be comma-separated. Specify either userIds, userNames, emails, aadGroupIds, entraGroupIds, aadGroupNames, or entraGroupNames.

--aadGroupIds [aadGroupIds]

(deprecated. Use entraGroupIds instead) The object ID of the Microsoft Entra group to add as a member. If multiple groups need to be added, the Ids have to be comma-separated. Specify either userIds, userNames, emails, aadGroupIds, entraGroupIds, aadGroupNames, or entraGroupNames.

--entraGroupNames [entraGroupNames]

The name of the Entra group to add as a member. If multiple groups need to be added, they have to be comma-separated. Specify either userIds, userNames, emails, aadGroupIds, entraGroupIds, aadGroupNames, or entraGroupNames.

--aadGroupNames [aadGroupNames]

(deprecated. Use entraGroupNames instead) The name of the Microsoft Entra group to add as a member. If multiple groups need to be added, they have to be comma-separated. Specify either userIds, userNames, emails, aadGroupIds, entraGroupIds, aadGroupNames, or entraGroupNames.

-h, --help [help]

Output usage information. Optionally, specify which section of command's help you want to see. Allowed values are options, examples, remarks, response, full. Default is options.

--query [query]

JMESPath query string. See http://jmespath.org/ for more information and examples.

-o, --output [output]

Output type. json, text, csv, md, none. Default json.

--verbose

Runs command with verbose logging.

--debug

Runs command with debug logging.

Remarks

For the userIds, userNames, emails, aadGroupIds, entraGroupIds, aadGroupNames, or entraGroupNames options you can specify multiple values by separating them with a comma. If one of the specified entries is not valid, the command will fail with an error message showing the list of invalid values.

Examples

Add a user with the userNames parameter to a SharePoint group with the groupId parameter.

m365 spo group member add --webUrl https://contoso.sharepoint.com/sites/SiteA --groupId 5 --userNames "Alex.Wilber@contoso.com"

Add multiple users with the userNames parameter to a SharePoint group with the groupId parameter.

m365 spo group member add --webUrl https://contoso.sharepoint.com/sites/SiteA --groupId 5 --userNames "Alex.Wilber@contoso.com, Adele.Vance@contoso.com"

Add a user with the emails parameter to a SharePoint group with the groupName parameter.

m365 spo group member add --webUrl https://contoso.sharepoint.com/sites/SiteA --groupName "Contoso Site Owners" --emails "Alex.Wilber@contoso.com"

Add multiple users with the emails parameter to a SharePoint group with the groupName parameter.

m365 spo group member add --webUrl https://contoso.sharepoint.com/sites/SiteA --groupName "Contoso Site Owners" --emails "Alex.Wilber@contoso.com, Adele.Vance@contoso.com"

Add a user with the userIds parameter to a SharePoint group with the groupId parameter.

m365 spo group member add --webUrl https://contoso.sharepoint.com/sites/SiteA --groupId 5 --userIds 5

Add multiple users with the userIds parameter to a SharePoint group with the groupId parameter.

m365 spo group member add --webUrl https://contoso.sharepoint.com/sites/SiteA --groupId 5 --userIds "5,12"

Add multiple users with the entraGroupIds parameter to a SharePoint group with the groupId parameter.

m365 spo group member add --webUrl https://contoso.sharepoint.com/sites/SiteA --groupId 5 --entraGroupIds "f2fb2f10-cfd2-4054-8ffd-64533657a5ab,3e86049e-89e6-4c27-bccb-d7549f0bbd06"

Add multiple users with the entraGroupNames parameter to a SharePoint group with the groupId parameter.

m365 spo group member add --webUrl https://contoso.sharepoint.com/sites/SiteA --groupId 5 --entraGroupNames "Azure group one, Azure group two" 

Response

[
{
"AllowedRoles": [
0
],
"CurrentRole": 0,
"DisplayName": "John Doe",
"Email": "john.doe@contoso.onmicrosoft.com",
"InvitationLink": null,
"IsUserKnown": true,
"Message": null,
"Status": true,
"User": "i:0#.f|membership|john.doe@contoso.onmicrosoft.com"
}
]
CTRL + M