Skip to content

New command: 🔐 spo file roleassignment add #3702

@Adam-it

Description

@Adam-it

Usage

m365 spo file roleassignment add [options]

Description

Adds a role assignment to the specified file.

Options

Option Description
-u, --webUrl <webUrl> The URL of the site where the file is located.
-f, --fileUrl [fileUrl] The server-relative URL of the file to which the role assignment will be added. Specify either fileUrl or fileId but not both.
-i, --fileId [fileId] The unique id (GUID) of the file to which the role assignment will be added. Specify either fileUrl or fileId but not both.
--principalId [principalId] The SharePoint principal id. It may be either an user id or group id to which the role assignment will be added. Specify either upn, groupName or principalId but not multiple.
--upn [upn] The upn/email of the user. Specify either upn, groupName or principalId but not multiple.
--groupName [groupName] The Azure AD or SharePoint group name. Specify either upn, groupName or principalId but not multiple.
--roleDefinitionId [roleDefinitionId] ID of the role definition. Specify either roleDefinitionId or roleDefinitionName but not both.
--roleDefinitionName [roleDefinitionName] The name of the role definition. E.g. 'Contribute', 'Read'. Specify either roleDefinitionId or roleDefinitionName but not both.

Examples

Add the role assignment to the specified file based on the group name.

m365 spo file roleassignment add --webUrl "https://contoso.sharepoint.com/sites/contoso-sales" --fileId "b2307a39-e878-458b-bc90-03bc578531d6"  --groupName "saleGroup"

Add the role assignment to the specified file based on the principal id.

m365 spo file roleassignment add --webUrl "https://contoso.sharepoint.com/sites/contoso-sales"  --fileUrl "/sites/project-x/documents/Test1.docx" --principalId 2

Additional Info

a very similar command was already developed but on list level, so we may probably use that command code as reference to make it easier to create this one
https://pnp.github.io/cli-microsoft365/cmd/spo/list/list-roleassignment-add/

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions