Forum Discussion
Powershell scripts for creating subsite in sharepoint online
Dahmeey Yes I tested there and it worked
- DahmeeyOct 15, 2019Copper ContributorVikram_Samal Would try it at work tomorrow and revert. Thanks alot
- DahmeeyOct 15, 2019Copper ContributorHi Vikram_Samal apologies for disturbing. May I know if you by any chance have the script to disable inheritance using the sharepoint management online tool?
- Vikram_SamalOct 15, 2019MCT
Dahmeey Please find the code:
#Create Subsite with Unique Permission and assign permisison to it
cls
$username = "myusername@mydomain.onmicrosoft.com"
$password = "mypassword"
$cred = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $userName, $(convertto-securestring $Password -asplaintext -force)
Connect-PnPOnline https://mydomain.sharepoint.com/sites/demo/ -cred $cred
New-PnPWeb -Title "SubSite B" -Url SubSiteB -Description "Information about SUBSITE B" -Locale 1033 -Template "STS#0" -BreakInheritance
$owner = (Get-PnPContext).Credentials.UserName
#The owner will be the person provisioning the groups#Create default groups for the new web and assign permisison
$ownerGroup = New-PnPGroup -Title "SubSite B Owners" -Owner $owner
Set-PnPWebPermission -Url SubSiteB -Group $ownerGroup -AddRole 'Full Control'$memberGroup = New-PnPGroup -Title "SubSite B Members" -Owner $owner
Set-PnPWebPermission -Url SubSiteB -Group $memberGroup -AddRole Contribute$visitorGroup = New-PnPGroup -Title "SubSite B Visitors" -Owner $owner
Set-PnPWebPermission -Url SubSiteB -Group $visitorGroup -AddRole ReadHope this helps!