How to Create a SharePoint Subsite using CSOM and Powershell in Sharepoint Online/SharePoint 2013/2016?

Hello SharePointers,

In this blog,we will see CSOM code to create a SharePoint subsite in Office 365.

$Username = Read-Host -Prompt “Please enter your username”
$Password = Read-Host -Prompt “Please enter your password” -AsSecureString
$Site = “https://mysite.sharepoint.com”
$Context = New-Object Microsoft.SharePoint.Client.ClientContext($Site)
$Creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username,$Password)
$Context.Credentials = $Creds

$WebCI = New-Object Microsoft.SharePoint.Client.WebCreationInformation
$WebCI.WebTemplate = “STS#0”
$WebCI.Description = “My own SubSite”
$WebCI.Title = ” My Baby SubSite”
$WebCI.Url = “SubSite”
$WebCI.Language = “1033”
$SubWeb = $Context.Web.Webs.Add($WebCI)
$Context.ExecuteQuery()

Happy SharePointing!!

Leave a Reply

Your email address will not be published. Required fields are marked *