kwizcom banner advertisement

SharePoint Online: How to Create a Subsite using PowerShell?

Requirement: Create a Subsite in SharePoint online using PowerShell.

How to create a Subsite in SharePoint Online?
To add a subsite in SharePoint online, follow these steps:
  • Sign-in to your SharePoint online site as Site Collection Administrator/Site Owner
  • Click on Site Settings Gear Icon >> Choose "Site Contents"
    sharepoint online powershell create subsite
  • Scroll down to the bottom and click on "Create Subsite" link
    sharepoint online powershell create web
  • Provide the Name, description, template for your new subsite. specify other optional settings such as Permissions, Navigation.
    how to create subsite in sharepoint online
  • Click on "Create" button at the bottom of the page to create a subsite in SharePoint online.
Lets see the SharePoint online PowerShell to create subsite.

SharePoint Online: PowerShell to create subsite:
Let's create a subsite in SharePoint online using PowerShell.
#Load SharePoint Online Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"

#Variables for processing
$SiteURL = "https://crescent.sharepoint.com/Sites/Sales"
$AdminAccount = "SPAdmin@crescent.com"
 
#User Names Password to connect 
$Password = Read-host -assecurestring "Enter Password for $AdminAccount" 
$Credential = new-object -typename System.Management.Automation.PSCredential -argumentlist $AdminAccount, $Password

Try {
    #Setup the context
    $Context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
    $Context.Credentials = $credentials

    #Specify Subsite details
    $WebCI = New-Object Microsoft.SharePoint.Client.WebCreationInformation
    $WebCI.Title = "Sales - US "
    $WebCI.WebTemplate = "STS#0" #Team Site
    $WebCI.Url = "us"
    $SubWeb = $Context.Web.Webs.Add($WebCI)
    $Context.ExecuteQuery()

    Write-host "Subsite Created Successfully!" -ForegroundColor Green
}
catch {
    write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
}
This script creates a web in SharePoint Online. The above script uses only mandatory parameters. You can refer this Technet link if you want to specify other parameters such as Permission, navigation settings, etc. https://msdn.microsoft.com/EN-US/library/office/microsoft.sharepoint.client.webcreationinformation_members.aspx

Tags: create subsite in sharepoint online using powershell, powershell sharepoint online new subsite, sharepoint online create new subsite, sharepoint online add subsite, sharepoint online create subsite csom, sharepoint online create subsite powershell, sharepoint online how to create subsite
SharePoint Online: How to Create a Subsite using PowerShell? SharePoint Online: How to Create a Subsite using PowerShell? Reviewed by Salaudeen Rajack on 1:45 PM Rating: 5

No comments:

Please Login and comment to get your questions answered!

Powered by Blogger.