Forum Discussion
SharePoint Online: Create subsite using PowerShell script based on CSOM or PnP
Bonjour Fabrice,
I followed the pnp powershell path but I am block with an access denied exception.
Set-PnPGroup -Identity 'Cours - Visiteurs' -SetAssociatedGroup Visitors -AddRole 'Read'
Set-PnPGroup : Access denied. You do not have permission to perform this action or access this resource.
Au caractère Ligne:1 : 9
+ Set-PnPGroup -Identity 'Cours - Visiteurs' -SetAssociatedGrou ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : WriteError: (:) [Set-PnPGroup], ServerUnauthorizedAccessException
+ FullyQualifiedErrorId : EXCEPTION,SharePointPnP.PowerShell.Commands.Principals.SetGroup
The group exist and I am connected (Connect-PnPOnline) as the tenant administrator who is also the owner of the sub site, the groups, etc. And I am using PnpPowerShellOnline 3.1.1809.0 from the PSGallery.
Do you had / have the same problem ?
Another point, my intent is to put the subsite provisionning in an Azure function. Is it better to use CSOM or PnP for stability reason.
Jean Marie
Dear Jean-Marie,
The part of the code "SetAssociatedGroup" is always the painful one.
It's mainly related to the modification Microsoft is doing on the SharePoint side (with the modern group sites).
This option is blocking without any real reason and the only way I found to execute it is to unlock the site before the command execution with that command:
- Set-SPOSite [RootSiteCollectionURL] -DenyAddAndCustomizePages 0
I'm really not sure that will help you in that case, but in many one it was the solution to.
Fab
- jmThiaOct 09, 2018Brass Contributor
No more authorization error while setting the default group !!
Thanks for the tip.
I will put the value back for now as I really can't image the side effect of this.