Create Subsite using PowerShell in SharePoint Online

Creating Sub Site in SPO

In my previous articles we learned how to create Site Collection in SharePoint Online now let us learn the next step creating sub sites using PowerShell. It is always a good idea to create sub sites to organize user content for better collaboration across the organization thought it is SharePoint online.

PowerShell Script to create sub site using PowerShell SharePoint Online:

The below script will create a sub site in SharePoint online:

function new-spOnlineWeb {

#variables that needs to be set before starting the script

$siteURL = “<< SharePoint Site Collection URL >>”

$webURL = “MyFirstWeb”

$title = “My First Web”

$template = “STS#0”

$userName = “<< User-ID >>”

$useSamePermissionsAsParentSite = $true

# Let the user fill in their password in the PowerShell window

$password = Read-Host “Please enter the password for $($userName)” -AsSecureString

# set SharePoint Online credentials

$SPOCredentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($userName, $password)

#Creating client context object

$context = New-Object Microsoft.SharePoint.Client.ClientContext($siteURL)

$context.credentials = $SPOCredentials

#create web using WebCreationInformatin object (wci)

$wci = New-Object Microsoft.SharePoint.Client.WebCreationInformation

$wci.url = $webURL

$wci.title = $title

$wci.webtemplate = $template

$wci.useSamePermissionsAsParentSite = $useSamePermissionsAsParentSite

$createWeb = $context.web.webs.add($wci)


#send the request containing all operations to the server



write-host “info: Creating $($title)” -foregroundcolor green



write-host “info: $($_.Exception.Message)” -foregroundcolor red




The below is the expected output:

How To Create A Sub Site In SharePoint Online
How To Create A Sub Site In SharePoint Online
Creating Sub Site in SPO
Creating Sub Site in SPO

Hope this helps, happy development in SharePoint Online !!!

Similar SharePoint 2013 Tutorials

Leave a Reply