SXA - create sites/tenants with SPE

Reading time ~1 minute

Learn how to automate site/tenant creation with PowerShell scripts

Introduction

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:

New-SxaSite.ps1

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

Asset Optimizer configuration

Explanation of different configuration options of SXA Asset Optimizer Continue reading

Items as resources and Unicorn

Published on November 21, 2021

Sitecore Extensions version 3.4 released

Published on November 07, 2020