The Sitecore Razl scripting engine has been completely re-designed. Sitecore Razl now uses PowerShell to script Razl operations. All operations available in the old scripting engine have been implemented as PowerShell cmdlets. In addtion to the high-level operation cmdlets, Sitecore Razl provides PowerShell cmdlets to perform all low-level operations Sitecore Razl uses. This allows the developer to create very robust scripts to manipulate the Sitecore items as they are copied between servers.
The Sitecore Razl PowerShell CmdLets require at least PowerShell 5.1
The Razl scripting module is imported into powershell by executing the powershell command:
import-module [Path to dll]\HedgehogDevelopment.RazlClient.dll -verbose
This will import all of the Razl scripting command into the current PowerShell session.
The Razl PowerShell CmdLets provide all of the same script functionality as previous versions of Razl, along with the flexibility of PowerShell. If you are looking for documentation on the previous version, please see: Razl XML Scripts
The Razl Powershell CmdLets need the customer Razl license to run in a build pipeline. This can be upplied using the environment variable RAZL_LICENSE_KEY. This key should be kept as a private environment variable because it contains the customers license key.
Connections define how Sitecore Razl should connect to a Sitecore instance. The connections are created with a PowerShell Cmdlet and are stored in a variable for later use.
Summary of Parameters:
The following is an example of creating a connection to Sitecore:
$sitecoreServer = Get-RazlConnection -SitecoreWebUrl <string> -DatabaseName <string> -AccessGuid <Guid>
This command creates a connection to the server specified by the -SitecoreWebUrl parameter. The connection object is stored in the $sitecoreServer variable and can be used as a parameter for other Sitecore Razl cmdlets.
In some cases, there may be a need to remove the connection from the Sitecore server. The cmdlet Remove-RazlConnection is provided to remove the connection from a server. This will remove the Service folder and the Sitecore Razl service assembly from the /bin folder, so it will cause the AppPool to recycle.
Summary of Parameters:
Here is an example of removing the connection from an existing connection
Remove-RazlConnection -Connection $connection
This assumes that $connection contains a properly initialized connection object where the -SitecoreServerRoot parameter was specified.
The Get-RazlConnectionStatus function allows the script to determine if a connection object is available for use.
Summary of Parameters:
The Get-RazlConnectionStatus returns on of the following values:
Ready, NotInstalled, OldVersion, InvalidAccessGuid, Deactivated, NeedCredentials, AccessDenied, ServerNotFound
Razl Operations are high-level functions that can be performed on a server or between two servers. Most operations are the same as tasks that can be added to the Task List in the Sitecore Razl UI. The full list of supported operations is:
The Copy-RazlItemsUsingHistory operation will replay the actions recorded in the Sitecore history engine on one instance on another instance. Razl uses the history engine or the search indexes to determine what has changed on the server. If these features are disabled or modified, the Copy-RazlItemsUsingHistory operation may not be able to acurately determine what has changed.
Summary of parameters:
The following is an example of using the Copy-RazlItemsUsingHistory cmdlet to move items from the source to target that have changed in the last 5 days:
$ErrorActionPreference = "Stop"
$InformationPreference = "Continue"
$source = Get-RazlConnection -SitecoreWebUrl http://source.sc.local -DatabaseName master -AccessGuid "00000000-1111-2222-3333-444444444444" -Name "Source Sitecore"
$target = Get-RazlConnection -SitecoreWebUrl http://target.sc.local -DatabaseName master -AccessGuid "00000000-1111-2222-3333-444444444444" -Name "Target Sitecore"
$last5Days = (Get-Date).AddDays(-5)
Copy-RazlItemsUsingHistory -source $source -target $target -from $last5Days -Description "Copy History" -verbose
The Copy-RazlItem operation will copy an item from the source Sitecore instance to the target Sitecore instance.
Summary of Parameters:
The following is an example of using the Copy-RazlItem cmdlet to copy the Home item from the source to target:
$ErrorActionPreference = "Stop"
$InformationPreference = "Continue"
$source = Get-RazlConnection -SitecoreWebUrl http://source.sc.local -DatabaseName master -AccessGuid "00000000-1111-2222-3333-444444444444" -Name "Source Sitecore"
$target = Get-RazlConnection -SitecoreWebUrl http://target.sc.local -DatabaseName master -AccessGuid "00000000-1111-2222-3333-444444444444" -Name "Target Sitecore"
Copy-RazlItem -source $source -target $target -ItemId "{110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9}" -verbose
This Example uses a PowerShell pipeline to copy all items under the home item:
$ErrorActionPreference = "Stop"
$InformationPreference = "Continue"
$source = Get-RazlConnection -SitecoreWebUrl http://source.sc.local -DatabaseName master -AccessGuid "00000000-1111-2222-3333-444444444444" -Name "Source Sitecore"
$target = Get-RazlConnection -SitecoreWebUrl http://target.sc.local -DatabaseName master -AccessGuid "00000000-1111-2222-3333-444444444444" -Name "Target Sitecore"
# Get-RazlChildItems returns an array of ItemProperty objects that contain basic information about each item under the ParentItemID.
# In this example, the array is converted into an array of ID's by pipeing it to the select statement.
# Next, it is sent to the Get-CopyItem Cmdlet to perform the copy.
Get-RazlChildItems -Connection $source -ParentItemID "{110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9}" -verbose | `
select -ExpandProperty Id | `
Copy-RazlItem -source $source -target $target -verbose
The Copy-RazlItemTree operation will copy an item and all child items from the source to the target.
Summary of Parameters:
The following is an example of using the Copy-RazlItemTree cmdlet to copy the Home item and all its children from the source to target:
$ErrorActionPreference = "Stop"
$InformationPreference = "Continue"
$source = Get-RazlConnection -SitecoreWebUrl http://source.sc.local -DatabaseName master -AccessGuid "00000000-1111-2222-3333-444444444444" -Name "Source Sitecore"
$target = Get-RazlConnection -SitecoreWebUrl http://target.sc.local -DatabaseName master -AccessGuid "00000000-1111-2222-3333-444444444444" -Name "Target Sitecore"
Copy-RazlItemTree -source $source -target $target -ItemId "{110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9}" -verbose -Overwrite -LightningMode -ContinueOnError
The Copy-RazlItemVersion operation will copy all fields in a specific version from an item on one server to another.
Summary of Parameters:
The following is an example of using the CopyVersion Cmdlet to copy version 1 of the Home item from source to target:
$ErrorActionPreference = "Stop"
$InformationPreference = "Continue"
$source = Get-RazlConnection -SitecoreWebUrl http://source.sc.local -DatabaseName master -AccessGuid "00000000-1111-2222-3333-444444444444" -Name "Source Sitecore"
$target = Get-RazlConnection -SitecoreWebUrl http://target.sc.local -DatabaseName master -AccessGuid "00000000-1111-2222-3333-444444444444" -Name "Target Sitecore"
Copy-RazlItemVersion -source $source -target $target -ItemId "{110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9}" -verbose -LanguageId "en" -VersionNum 1