Skip to content

Instantly share code, notes, and snippets.

@tristian2
Last active September 7, 2018 10:20
Show Gist options
  • Save tristian2/132c14c576680d2dcdb731536ca4ad8e to your computer and use it in GitHub Desktop.
Save tristian2/132c14c576680d2dcdb731536ca4ad8e to your computer and use it in GitHub Desktop.
subsite default groups association demo why it doesnt work
Clear-Host
#my tenancy
#based upon
#https://sharepoint.stackexchange.com/questions/239489/sharepoint-pnp-powershell-how-to-provision-sub-webs-with-unique-permissions-an
#at this poiint this doesn not setup the association, so it doesnt work. sets up the groups nicely though
$UserName= "tristian2@******.onmicrosoft.com"
$Password = "*******"
$SiteUrl = "https://******.sharepoint.com"
$subsite = "testSubSite"
$subsiteTitle = "test SubSite"
$subSiteUrl = "$SiteUrl/$subsite"
$Credentials = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $userName, $(convertto-securestring $Password -asplaintext -force)
Connect-PnPOnline -Url $SiteUrl -Credentials $Credentials
#remove if already there...
Remove-PnPWeb -Url $subSite -Force
New-PnPWeb -Title $subsiteTitle -Url "testSubSite" -Description "we want to setup a new subsite to make sure that sharing works for it, in order to do that, we ensure certian OOB groups are present" `
-Locale 1033 -Template "STS#0" -BreakInheritance
$owner = (Get-PnPContext).Credentials.UserName
#Create default groups for the new web
#here, by default owner will be the person provisioning the groups
$ownerGroup = New-PnPGroup -Title "$subsiteTitle Owners" -Owner $owner
Set-PnPGroup -Identity $ownerGroup -SetAssociatedGroup Owners
$memberGroup = New-PnPGroup -Title "$subsiteTitle Members" -Owner $owner
Set-PnPGroup -Identity $memberGroup -SetAssociatedGroup Members
$visitorGroup = New-PnPGroup -Title "$subsiteTitle Visitors" -Owner $owner
Set-PnPGroup -Identity $visitorGroup -SetAssociatedGroup Visitors
#Apply template with groups. Templates applies OK, but groups are not defined
#Apply-PnPProvisioningTemplate -Path C:\ProjectSiteTemplate.xml -Web projectB
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment