Skip to content

[BUG] The Set-PnPPropertyBagValue command is treated as an AdminCmdlet no matter how it is used #5159

@julien-iseli-fr-ch

Description

@julien-iseli-fr-ch

Reporting an Issue or Missing Feature

The Set-PnPPropertyBagValue command is classified as an AdminCmdlet regardless of how it is used, which causes it to attempt a connection to the SharePoint Online Admin Center even when a tenant admin URL is not specified.

Relevant source code:

public class SetPropertyBagValue : PnPSharePointOnlineAdminCmdlet

// No explicit SharePoint Online Admin Center URL has been provided in the connect, try to guess it using the default <tenant>-admin.sharepoint.<tld> syntax

AdminContext = Connection.CloneContext(tenantAdminUrl);

Expected behavior

The command should be permitted as a non-admin Cmdlet when it targets a specific site and the AllowWebPropertyBagUpdateWhenDenyAddAndCustomizePagesIsEnabled setting is enabled for the tenant.

References:

https://learn.microsoft.com/en-us/powershell/module/microsoft.online.sharepoint.powershell/set-spotenant?view=sharepoint-ps#-allowwebpropertybagupdatewhendenyaddandcustomizepagesisenabled

Actual behavior

The command fails with the following error when trying to update property bag values on a site using a service principal with FullControl permission for the site but lacking permission at the tenant level:

Unable to connect to the SharePoint Online Admin Center at 'https://MYTENANT-admin.sharepoint.com'/ to run this cmdlet. If this URL is incorrect for your tenant, you can pass in the correct Admin Center URL using Connect-PnPOnline -TenantAdminUrl. If you are using Privileged Identity Management (PIM) on your tenant, please ensure you have activated at least the SharePoint Administrator role and allowed some time for it to activate. Error message: Attempted to perform an unauthorized operation.

Steps to reproduce behavior

Run the following command while connected with an account or service principal that does not have tenant admin permissions:

Set-PnPPropertyBagValue -Key "MyKey" -Value "MyValue" -Connection $PnPConnection

What is the version of the Cmdlet module you are running?

This issue is present in all versions tested, including up to nightly-3.1.196.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions