pnp / cli-microsoft365

Manage Microsoft 365 and SharePoint Framework projects on any platform
https://aka.ms/cli-m365
MIT License
882 stars 312 forks source link

New command: `m365 spo site admin add` #5883

Open MathijsVerbeeck opened 4 months ago

MathijsVerbeeck commented 4 months ago

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

martinlingstuyl commented 4 months ago

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.

MathijsVerbeeck commented 4 months ago

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?

martinlingstuyl commented 4 months ago

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

MathijsVerbeeck commented 4 months ago

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

Adam-it commented 4 months ago

LGTM 👍👏

mkm17 commented 2 months ago

Hi, could you assign me to this task?

mkm17 commented 1 month ago

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?