Had a search for other 403 posts but couldn't see any related to this. I'm using the MS code snippet here to provision a modern team site using PnP CSOM (essentially create a group, delete a group). I'm running this from PnP Partner Pack with some customisations to support this modern site creation (namely just if BaseTemplate="GROUP#0" create modern site in this way).
When the site is first created all appears to be well, but shortly afterwards I get a 403 as the site has been set to have LockState NoAccess. I can unlock the site using the PowerShell here , but I'm hoping for this solution to be a way for users to create their own sites automatically so don't want to have admins needing to run some PowerShell manually afterwards. This has happened on 2 different tenants with 4 sites all provisioned in this way.
Has anyone else seen this behaviour? I wondered if it was because the suggested code deleted the group afterwards, so I've commented out the line:
And so far the site hasn't entered the NoAccess state.
It would make sense if deleting a group put the related team site into a NoAccess state, but then why would this be the suggested code if this was the cause?
Edit - To provide all information I should also say I also run a PnP Template against the site after its provisioned which sets a composed look, a CustomAction, turns on site policy feature and attempts to set that policy. Nothing too complex. To allow the CustomAction to work I also have to run DisableDenyAddCustomizePages.
My "non deleted group" modern site is still accessible. One other thing I notice is the site settings on this site seem to be completely mashed: