powershell: [BUG] - Adding Site Collection Admins using Set-PnPTenantSite throws unauthorized error
Notice
Many bugs reported are actually related to the PnP Framework which is used behind the scenes. Consider carefully where to report an issue:
- Are you using
Invoke-PnPSiteTemplateorGet-PnPSiteTemplate? The issue is most likely related to the Provisioning Engine. The Provisioning engine is not located in the PowerShell repo. Please report the issue here: https://github.com/pnp/pnpframework/issues. - Is the issue related to the cmdlet itself, its parameters, the syntax, or do you suspect it is the code of the cmdlet that is causing the issue? Then please continue reporting the issue in this repo.
- If you think that the functionality might be related to the underlying libraries that the cmdlet is calling (We realize that might be difficult to determine), please first double check the code of the cmdlet, which can be found here: https://github.com/pnp/powershell/tree/master/src/Commands. If related to the cmdlet, continue reporting the issue here, otherwise report the issue at https://github.com/pnp/pnpframework/issues
Reporting an Issue or Missing Feature
Reporting an issue with setting owners for a sitecollection using Set-PnPTenantSite
Expected behavior
Adding a user with SharePoint Admin role to all the site collections as admin using Set-PnPTenantSite -Identity <> -Owners <> cmdlet
Actual behavior
Get an error “Set-PnPTenantSite: Attempted to perform an unauthorized operation.”
Steps to reproduce behavior
Run under a context of user with SharePoint Admin role assigned Use Connect-PnPOnline to connect to SiteCollection to which the admin should be added as SiteCollectionAdmin Use Set-PnPTenantSite to add a user as SiteCollectionAdmin Error : “Set-PnPTenantSite: Attempted to perform an unauthorized operation.”
What is the version of the Cmdlet module you are running?
1.6.26-nightly
Which operating system/environment are you running PnP PowerShell on?
- Windows
- Linux
- [ X] MacOS
- Azure Cloud Shell
- Azure Functions
- Other : please specify
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 15 (1 by maintainers)
@gautamdsheth - Adding on to what @siddharth-vaghasia stated. According to the docs link below we would use Set-PnPTenantSite when we are not a site collection admin of the site and use Add-PnPSiteCollectionAdmin if we are already an admin on that SC. https://docs.microsoft.com/en-us/powershell/module/sharepoint-pnp/add-pnpsitecollectionadmin?view=sharepoint-ps
@gautamdsheth - In my case, I am first connecting to SharePoint Admin URL with user credential who is SharePoint Admin… and so ideally all future commands should run under the context of the SharePoint Admin…
Also, I can confirm that the same script and command works fine in the legacy module ‘SharePointPnPPowerShellOnline’… For now, I have moved to the older module…it is just I think the same thing should supported in the new version also…