import Global from '../../_global.mdx';
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

# spo group member add

Adds members to a SharePoint Group

## Usage

```sh
m365 spo group member add [options]
```

## Options

```md definition-list
`-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`, `entraGroupIds` or `entraGroupNames`.

`--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`, `entraGroupIds` or `entraGroupNames`.

`--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`, `entraGroupIds` or `entraGroupNames`.

`--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`, `entraGroupIds` 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`, `entraGroupIds` or `entraGroupNames`.
```

<Global />

## Remarks

For the `userIds`, `userNames`, `emails`, `entraGroupIds`, 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.

```sh
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.

```sh
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.

```sh
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.

```sh
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.

```sh
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.

```sh
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.
  
```sh 
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.
  
```sh 
m365 spo group member add --webUrl https://contoso.sharepoint.com/sites/SiteA --groupId 5 --entraGroupNames "Azure group one, Azure group two" 
```

## Response

<Tabs>
  <TabItem value="JSON">

  ```json
  [
    {
      "Id": 11,
      "IsHiddenInUI": false,
      "LoginName": "i:0#.f|membership|adelev@contoso.onmicrosoft.com",
      "Title": "Adele Vance",
      "PrincipalType": 1,
      "Email": "Adele.Vance@contoso.onmicrosoft.com",
      "Expiration": "",
      "IsEmailAuthenticationGuestUser": false,
      "IsShareByEmailGuestUser": false,
      "IsSiteAdmin": false,
      "UserId": {
        "NameId": "10032001f5ac2029",
        "NameIdIssuer": "urn:federation:microsoftonline"
      },
      "UserPrincipalName": "adelev@contoso.onmicrosoft.com"
    }
  ]
  ```

  </TabItem>
  <TabItem value="Text">

  ```text
  Email                         : Adele.Vance@contoso.onmicrosoft.com
  Expiration                    : 
  Id                            : 11
  IsEmailAuthenticationGuestUser: false
  IsHiddenInUI                  : false
  IsShareByEmailGuestUser       : false
  IsSiteAdmin                   : false
  LoginName                     : i:0#.f|membership|adelev@contoso.onmicrosoft.com
  PrincipalType                 : 1
  Title                         : Adele Vance
  UserId                        : {"NameId":"10032001f5ac2029","NameIdIssuer":"urn:federation:microsoftonline"}
  UserPrincipalName             : adelev@contoso.onmicrosoft.com
  ```

  </TabItem>
  <TabItem value="CSV">

  ```csv
  Id,IsHiddenInUI,LoginName,Title,PrincipalType,Email,Expiration,IsEmailAuthenticationGuestUser,IsShareByEmailGuestUser,IsSiteAdmin,UserPrincipalName
  11,,i:0#.f|membership|adelev@contoso.onmicrosoft.com,Adele Vance,1,Adele.Vance@contoso.onmicrosoft.com,,,,,adelev@contoso.onmicrosoft.com
  ```

  </TabItem>
  <TabItem value="Markdown">

  ```md
  # spo group member add --webUrl "https://contoso.sharepoint.com/sites/Marketing" --groupId "5" --userNames "AdeleV@contoso.onmicrosoft.com"

  Date: 10/07/2024

  ## Adele Vance (11)

  Property | Value
  ---------|-------
  Id | 11
  IsHiddenInUI | false
  LoginName | i:0#.f\|membership\|adelev@contoso.onmicrosoft.com
  Title | Adele Vance
  PrincipalType | 1
  Email | Adele.Vance@contoso.onmicrosoft.com
  Expiration |
  IsEmailAuthenticationGuestUser | false
  IsShareByEmailGuestUser | false
  IsSiteAdmin | false
  UserPrincipalName | adelev@contoso.onmicrosoft.com
  ```

  </TabItem>
</Tabs>
