Learn how to automate site/tenant creation with PowerShell scripts
Did you know that all scaffolding dialogs were created with Sitecore Powershell Extensions?
The fact that scaffolding use PowerShell to create sites and tenants is a great news for us.
This means that we can very easy automate this process!
You can find code here:
There are three sections:
variables- you can set different values. If you invoke it in a loop you can change for example site name (S1, S2, …),
create - new tenant- creates a tenant with default settings,
create - new site- creates a site with default settings
Script will create a tenant folder F.
Under F folder a new tenant T with site S will be created
Tenant and site will be created with all default features (modules which are marked as
Include by default).
Bonus - cleanup
If you need to remove a tenant folder you can use this snippet
1 2 3 4 5 Import-Function Remove-TenantFolder $contentPath = "master:/content/F" $folder = Get-Item -Path $contentPath Remove-TenantFolder $folder
What is the point of removing it this way? Script will take care of everything. It will not only remove content items but also templates and media library.
There are other cmdlets that you can use as well.
1 2 3 Import-Function Remove-TenantFolder Import-Function Remove-Tenant Import-Function Remove-Site