Skip to content

New command: spo user add #1690

@VelinGeorgiev

Description

@VelinGeorgiev

Usage

spo user add [options]

Description

Adds user to a specific web

Options

Option Description
-u, --webUrl <webUrl> Url of the web to list the users within
--email <email> Email of the user to be added
--group <group> The SharePoint group name to which the user to be added
-o, --output [output] Output type. json,text. Default text
--verbose Runs command with verbose logging
--debug Runs command with debug logging

Example

Adds user with email [email protected] to the Viewers group of web https://contoso.sharepoint.com/sites/mysite

spo user add --webUrl "https://contoso.sharepoint.com/sites/mysite" --email "[email protected]" --group "Team Site Members"

SOAP APIs reference

Unfortunately, there isn't a REST API for adding users. The SOAP API can be used to achieve this in two calls.

The first call would get the SharePoint group id and the http call looks like this.

POST /_vti_bin/client.svc/ProcessQuery

BDOY
`<Request AddExpandoFieldTypeSuffix="true" SchemaVersion="15.0.0.0" LibraryVersion="16.0.0.0" ApplicationName="${config.applicationName}" xmlns="http://schemas.microsoft.com/sharepoint/clientquery/2009"><Actions><ObjectPath Id="16" ObjectPathId="15" /><ObjectIdentityQuery Id="17" ObjectPathId="15" /><Query Id="18" ObjectPathId="15"><Query SelectAllProperties="true"><Properties /></Query></Query><ObjectPath Id="20" ObjectPathId="19" /><Query Id="21" ObjectPathId="19"><Query SelectAllProperties="true"><Properties /></Query><ChildItemQuery SelectAllProperties="true"><Properties /></ChildItemQuery></Query></Actions><ObjectPaths><Method Id="15" ParentId="5" Name="GetByName"><Parameters><Parameter Type="String">Team Site Members</Parameter></Parameters></Method><Property Id="19" ParentId="15" Name="Users" /><Property Id="5" ParentId="3" Name="SiteGroups" /><Property Id="3" ParentId="1" Name="Web" /><StaticProperty Id="1" TypeId="{3747adcd-a3c3-41b9-bfab-4a64dd2f1e0a}" Name="Current" /></ObjectPaths></Request>`

where Team Site Members value in the XML has to be replaced by the --group option value specified by the user of the CLI.

The second call would use the group id returned by the first call to add the user to the group

POST /_vti_bin/client.svc/ProcessQuery

BDOY
`<Request AddExpandoFieldTypeSuffix="true" SchemaVersion="15.0.0.0" LibraryVersion="16.0.0.0" ApplicationName="${config.applicationName}" xmlns="http://schemas.microsoft.com/sharepoint/clientquery/2009"><Actions><ObjectPath Id="28" ObjectPathId="27" /><ObjectIdentityQuery Id="29" ObjectPathId="27" /></Actions><ObjectPaths><Method Id="27" ParentId="19" Name="AddUser"><Parameters><Parameter ObjectPathId="25" /></Parameters></Method><Property Id="19" ParentId="15" Name="Users" /><Method Id="25" ParentId="3" Name="EnsureUser"><Parameters><Parameter Type="String">[email protected]</Parameter></Parameters></Method><Identity Id="15" Name="65df629f-d0f6-2000-295f-0aa52be8fdc4|740c6a0b-85e2-48a0-a494-e0f1759d4aa7:site:ed45f182-74d9-4b2a-abf7-c39b4a2f0a29:g:7" /><Property Id="3" ParentId="1" Name="Web" /><StaticProperty Id="1" TypeId="{3747adcd-a3c3-41b9-bfab-4a64dd2f1e0a}" Name="Current" /></ObjectPaths></Request>`

where [email protected] is the --email option and the 65df629f-d0f6-2000-295f-0aa52be8fdc4|740c6a0b-85e2-48a0-a494-e0f1759d4aa7:site:ed45f182-74d9-4b2a-abf7-c39b4a2f0a29:g:7 value is the group id from the first request.

Additional Information

Add-SPOUser -
https://docs.microsoft.com/en-us/powershell/module/sharepoint-online/add-spouser?view=sharepoint-ps

Add-PnPUserToGroup -
https://docs.microsoft.com/en-us/powershell/module/sharepoint-pnp/add-pnpusertogroup?view=sharepoint-ps

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions