SXA - create sites/tenants with SPE

Reading time ~1 minute

Learn how to automate site/tenant creation with PowerShell scripts


If you ever created a site or tenant in SXA you probably know this dialog

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!

Powershell power

Script source

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

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.

Import-Function Remove-TenantFolder
Import-Function Remove-Tenant
Import-Function Remove-Site

Sitecore Utilities: Cache Viewer

Utility used to scan Sitecore cache. You can inspect cache details and view or remove particular cache entries. Continue reading

Sitecore Utilities: Unicorn Packaging

Published on January 29, 2019

SXA Health Check

Published on October 22, 2018