I would not suggest you to use Powershell script for creating one to two sub sites but if you are doing consultancy and have to create site information architecture which can involve number of sub sites then it would be a time taking job if you are going to create them through SharePoint environment.
Here I am sharing a PowerShell script which can be used for creation of a SharePoint online, and you can use it in scenarios where you have to create an information architecture which involve multiple subsites at different levels. Customize the script as per your requirement and you can create all sites with minimum effort and this script can be used for multiple assignments.
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"
#*** you can also move below line outside the function to get rid of login again if you need to call the function multiple time. ***
$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($siteURL)
$credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
$ctx.Credentials = $credentials
Write-host "Creating new site ..."
$newWeb = New-Object Microsoft.SharePoint.Client.WebCreationInformation
$newWeb.Title = "Sales - US "
$newWeb.WebTemplate = "STS#0" #Team Site
$newWeb.Url = "hr"
$sWeb = $ctx.Web.Webs.Add($newWeb)
Write-host "the site is created Successfully"
In above script I have created a function createNewSite which take site url as parameter where it will create the site. Below is the function call:
Note: You need full control on the site for creation of a new sub site.
Latest posts by Adnan Amin (see all)
- Five ways to get OneDrive URL for a User in Microsoft 365 - March 1, 2020
- OneDrive Sync issue: SharePoint Documents Library not syncing - February 12, 2020
- Teamwork in Microsoft 365 - September 18, 2019