Aug 25 2017 12:15 PM
Hi all,
I am working on a provisioning script that will allow me to create Modern SharePoint Team Sites and apply a provisioning template to them after, all of this in PowerShell Cmdlets.
I create my Modern Team Site by creating a new Unified Group (New-PnPUnifiedGroup cmdlet).
I need to add an member to the Owner Group of the SharePoint site but I can't seem to make it work. The only way I have been able to achieve this is by applying a provisioning template that adds the user to the admin group. The problem with this is that it takes a random amount of time between 5 minutes and 5 hours before I can apply the template to my newly created site (before that, I always get ''Access Denied'' errors).
I have tried $tenant.SetSiteAdmin(), Set-SPOUser -IsSiteCollectionAdmin and a few other things, but nothing has worked yet.
Is there a way to know how this is done in the code of the Apply-PnPProvisioningTemplate cmdlet?
Aug 30 2017 06:41 PM
SolutionYou can use the "Add-PnPUserToGroup" PnP Powershell cmdlet to handle this.
https://github.com/SharePoint/PnP-PowerShell/blob/master/Documentation/AddPnPUserToGroup.md
Link to download powershell cmdlets:
https://github.com/SharePoint/PnP-PowerShell/releases
Aug 31 2017 07:01 AM
Hi @Drew Madelung,
I did try this before and it added my user to the Owner group, but it still says ''access denied'' when I try to apply the provisioning template.
Perhaps it could be that the access token has not been refreshed/renewed?
Aug 31 2017 08:32 AM
Aug 31 2017 11:40 AM
@Drew Madelung That's correct. I have been digging a little bit more and I believe the problem is related to the template itself. I think the site has not been completely created just yet when I am applying the template.
I have the following nodes:
<pnp:Files> <pnp:File src="..\SiteAssets\Test.txt" Folder="SiteAssets" /> <pnp:File src="..\SiteAssets\logo.png" Folder="SiteAssets" /> </pnp:Files>
And see this in the detailed logs: "Creating folder 'SiteAssets' under Web '/sites/MyModernSite19/'"
2017-08-31 10:31:15.0785 [Files] [13] [Debug] Code execution scope started 0ms 8614b127-0a77-4b98-942b-c298d9ac31e9
2017-08-31 10:31:16.1248 [OfficeDevPnP.Core] [0] [Information] Creating folder 'SiteAssets' under Web '/sites/MyModernSite19/'. 0ms
2017-08-31 10:31:16.2582 [Files] [13] [Debug] Code execution scope ended 1180ms 8614b127-0a77-4b98-942b-c298d9ac31e9
2017-08-31 10:31:16.2592 [Provisioning] [13] [Debug] Code execution scope ended 6993ms 8614b127-0a77-4b98-942b-c298d9ac31e9
I believe the access Denied error means that I cannot create the folder SiteAssets under Web, not that I can't apply the template.
Aug 31 2017 01:38 PM
Update: The Site Assets folder is only created once the user browses to the site (in the UI).
Would there be a way to fake that browsing action? Possibly a Web Request?
Sep 05 2017 08:09 AM
Update 2:
This worked for me
$context = Get-PnPContext $web = Get-PnPWeb $web.Lists.EnsureSiteAssetsLibrary() $web.Context.ExecuteQuery()
May 13 2020 05:13 AM
This also worked for me - however the context operations were unnecessary.
Aug 30 2017 06:41 PM
SolutionYou can use the "Add-PnPUserToGroup" PnP Powershell cmdlet to handle this.
https://github.com/SharePoint/PnP-PowerShell/blob/master/Documentation/AddPnPUserToGroup.md
Link to download powershell cmdlets:
https://github.com/SharePoint/PnP-PowerShell/releases