cli-microsoft365 icon indicating copy to clipboard operation
cli-microsoft365 copied to clipboard

New command: `m365 spo site admin add`

Open MathijsVerbeeck opened this issue 11 months ago • 7 comments

Usage

m365 spo site admin add [options]

Description

Adds a user or group as a site collection administrator

Options

Option Description
-u, --siteUrl <siteUrl> The URL of the site
--userId [userId] The ID of the user to add as a site collection admin
--userName [userName] The user principal name of the user to add as a site collection admin
--groupId [groupId] The ID of the Microsoft Entra ID group to add as a site collection admin
--groupName [groupName] The name of the Microsoft Entra ID group to add as a site collection admin
--primary If set, will add the user as primary site collection admin. The old primary site collection admin will be replaced and set as secondary site collection admin
--asAdmin If specified, we will use the SharePoint admin center to execute the command

Examples

Add user as primary site collection administrator

m365 spo site admin add --siteUrl https://contoso.sharepoint.com --userId 600713c5-53c6-4f24-b454-3c35e22b2639 --primary

Adds group as secondary site collection administrator

m365 spo site admin add --siteUrl https://contoso.sharepoint.com --groupName SP_Administrators

Response

This command has no response

MathijsVerbeeck avatar Mar 05 '24 15:03 MathijsVerbeeck

I really love these command-specs @mathijsverbeeck! That will be really helpful.

I think it would be important with this set of commands that it should be possible to execute them if you are a SharePoint administrator and not yourself a site collection admin or owner of the site in question.

So, you'd need to be able to add yourself or others as an admin, even if you're currently not.

martinlingstuyl avatar Mar 06 '24 15:03 martinlingstuyl

I think it would be important with this set of commands that it should be possible to execute them if you are a SharePoint administrator and not yourself a site collection admin or owner of the site in question.

So, you'd need to be able to add yourself or others as an admin, even if you're currently not.

I agree, and I think that we could add an option --asAdmin that we could use when we run in a delegated context, so that we make sure that we use the admin center for adding the site collection administrator. What do you think about this?

MathijsVerbeeck avatar Mar 06 '24 15:03 MathijsVerbeeck

I agree, and I think that we could add an option --asAdmin that we could use when we run in a delegated context, so that we make sure that we use the admin center for adding the site collection administrator. What do you think about this?

I like that!. Also check out my other comment here: https://github.com/pnp/cli-microsoft365/issues/5882#issuecomment-1981160284

martinlingstuyl avatar Mar 06 '24 15:03 martinlingstuyl

@martinlingstuyl I have updated the specs to include the --asAdmin flag.

MathijsVerbeeck avatar Mar 06 '24 15:03 MathijsVerbeeck

LGTM 👍👏

Adam-it avatar Mar 06 '24 15:03 Adam-it

Hi, could you assign me to this task?

mkm17 avatar May 08 '24 14:05 mkm17

Hi everyone, I have a quick question about setting a --primary site collection admin without using --asAdmin mode. I found a method to do this with the _vti_bin/client.svc/ProcessQuery endpoint, but when I run it, the previous primary site collection admin is removed. I have checked the behavior of PnP.PowerShell, and the effect is the same. I have also tried using the _api/site/owner endpoint, but it does not give any results. In --asAdmin mode, I have managed it, and it works correctly.

What do you suggest? Is it better to leave it with the removal behavior and include information about this in the parameter description?

Or perhaps it is better to get the previous primary site collection admin beforehand, set the primary admin (which would remove the previous admin), and then reassign the previous admin as secondary site collection admin?

mkm17 avatar May 23 '24 07:05 mkm17