Oct 15 2019 09:49 AM
Oct 15 2019 01:25 PM - edited Oct 15 2019 01:27 PM
@Dahmeey The code for creating sub site is
$username = "vsamal@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 A" -Url SubSiteA -Description "Information about SUBSITE A" -Locale 1033 -Template "STS#0"
Then the output comes like this:
Hope this helps!
Oct 15 2019 01:50 PM
Oct 15 2019 01:52 PM
@Dahmeey Yes I tested there and it worked
Oct 15 2019 01:54 PM
Oct 15 2019 02:12 PM
Oct 15 2019 03:35 PM - edited Oct 15 2019 03:40 PM
Please find the break inheritance and permission assign 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 <a href="https://mydomain.sharepoint.com/sites/demo/" target="_blank">https://mydomain.sharepoint.com/sites/demo/</a> -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 Read
Hope this helps!
Oct 15 2019 03:41 PM
@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 Read
Hope this helps!
Oct 15 2019 11:25 PM
Oct 16 2019 01:32 AM
Oct 16 2019 01:43 PM
@Dahmeey You can always install the Pnp PowerShell assembly in your system from here:
Thanks for confirming that it worked for you!