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)
- SharePoint folder deletion error: Cannot delete/checked out issue - March 5, 2019
- Get list of all hidden lists in a SharePoint Site - February 27, 2019
- SharePoint Modern UI: Using Sites web part page - February 19, 2019