Sometimes it happens that you need to create Bulk subsites in a Site collection. And there is one thing what it-ers don’t like and that is manual work.
With this PowerShell script you can use a EXCEL.CSV to import as many sites as you want.
Step1
First of all you need to install the SharePoint2013 Client Components SDK.
http://www.microsoft.com/en-au/download/details.aspx?id=35585
Step2
The next step is to start up powershell ISE as a Administrator.
Now we need to make a connection to you Office365 admin Tenant with the following command
connect-SPOservice https://tenantname.admin.sharepoint.com
Fill in your Office365 administrator credentials and press OK.
Now you are connected to you SharePoint tenant.
Step 3
And we can start editing the script to import the CSV.
Copy the following script in your Powershell script pane.
$csvLocation = “C:\Installt\sites.csv”
$template = “template”
$siteUrl = “https://tenant.sharepoint.com/sites/sitecollection”
$username = “youraccount@tenant.nl”#yourpassword
Add-Type -Path “c:\Microsoft.SharePoint.Client.dll”
Add-Type -Path “c:\Microsoft.SharePoint.Client.Runtime.dll”$password = Read-Host -Prompt “Enter password” -AsSecureString
$ctx = New-Object Microsoft.SharePoint.Client.ClientContext ($siteUrl)
$credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $password)
$ctx.Credentials = $credentials
$csv = Import-Csv $csvLocationForEach ($site in $csv) {
$site = $($site.collumname of CSV)
$webCreationInformation = New-Object Microsoft.SharePoint.Client.WebCreationInformation
$webCreationInformation.Url = $site
$webCreationInformation.Title = $site
$webCreationInformation.WebTemplate = $template
$newWeb = $ctx.Web.Webs.Add($webCreationInformation)
$newWeb.ResetRoleInheritance()
$ctx.Load($newWeb)
$ctx.ExecuteQuery()Write-Host “Site created:” $newWeb.Title ” at: ” $siteUrl “/” $newWeb.Url
}
Now you probably wonder what you need top fill in at Template. You can choos a custom template or you can choose one of the template from the site bellow.
https://j3rmeyer.wordpress.com/2015/06/22/template-codes-overview/
In the next couple of days i will create another blog about this subject where i show you how to create a Custom template and how you can get the template code of your custom template.
Good luck and don’t hesitate to ask me question about this subject.