Skip to content

Instantly share code, notes, and snippets.

@michaellwest
michaellwest / DownloadLogs.ps1
Created June 18, 2025 17:01
Download all log files using Sitecore PowerShell Extensions (SPE).
Import-Function -Name Compress-Archive
# The archive filename will closely resemble the format of the default logfile names.
$archiveName = "logs.$([datetime]::Now.ToString("yyyy-MM-dd.HHmmss"))"
$archiveDirectory = "$($SitecoreDataFolder)\archived\"
$logDirectory = "$($SitecoreDataFolder)\logs\"
$archivePath = Join-Path -Path $archiveDirectory -ChildPath $archiveName
Compress-Archive -Path $logDirectory –CompressionLevel Fastest -DestinationPath $archivePath | Out-Download
@michaellwest
michaellwest / SitecoreRegistry.ps1
Created June 18, 2025 17:00
Writes settings to the Sitecore registry using Sitecore PowerShell Extensions (SPE).
$previouslySelectedKey = "previously.selected.databases"; #you should change this to something that makes sense to you
$previouslySelectedString = [Sitecore.Web.UI.HtmlControls.Registry]::GetString($previouslySelectedKey);
$previouslySelected = $previouslySelectedString.Split(",");
$targets = [ordered]@{"Web"="web"; "Preview"="webpreview"};
$props = @{
Parameters = @( @{ Name="selectedTargets"; Title="Choose Targets"; Editor="checklist"; Options=$targets; Value=$previouslySelected; Tooltip = "Select one or more targets" } )
Title = "Publish Item and Local Data"
Description = "Select the relevant publishing settings for the item."
Width = 500
@michaellwest
michaellwest / HangfireRecurringJobs.ps1
Last active March 28, 2025 16:20
Precision scheduling for Sitecore using Hangfire. Replaces the out of the box Scheduled Task feature.
$connection = [Hangfire.JobStorage]::Current.GetConnection()
$recurringJobs = [Hangfire.Storage.StorageConnectionExtensions]::GetRecurringJobs($connection)
$props = @{
Title = "Hangfire Recurring Jobs"
InfoTitle = "Recurring Jobs Report"
InfoDescription = "This report provides details on the currently scheduled recurring jobs."
PageSize = 25
Property = @(
"Id",
@michaellwest
michaellwest / Merge-XdtTransform.ps1
Last active February 22, 2025 07:38
Pure PowerShell script to apply an XDT transform with a typicaly web.config found in ASP.Net.
function Merge-XdtTransform {
<#
.SYNOPSIS
A function to apply Xml Configuration Transforms without the need for Microsoft.Web.XmlTransform.dll.
.NOTES
Michael West
.EXAMPLE
Merge-XdtTransform -Base $xmlBase -Transform $xmlTransform
@michaellwest
michaellwest / CleanupTables.sql
Last active August 29, 2024 18:10
Remove entries in the Sitecore Publishing Service queue using PowerShell.
Import-Function -Name Invoke-SqlCommand
$connection = [Sitecore.Configuration.Settings]::GetConnectionString("master")
$query = @"
DELETE FROM [Sitecore.Masterx].[dbo].[Publishing_ActivationLock]
DELETE FROM [Sitecore.Masterx].[dbo].[Publishing_Data_Params_FieldIds]
DELETE FROM [Sitecore.Masterx].[dbo].[Publishing_Data_Params_Languages]
DELETE FROM [Sitecore.Masterx].[dbo].[Publishing_JobManifest]
DELETE FROM [Sitecore.Masterx].[dbo].[Publishing_JobMetadata]
@michaellwest
michaellwest / CleanUnusedBlobs.sql
Last active August 7, 2024 20:04
Count and remove the unused blobs for Sitecore 10.2. Replaces the use of https://gist.github.com/michaellwest/51f4bcaf93400649b5482cf061d0e869
/* Modified version of the cleanup script provided by Sitecore Support. This version runs with a counter to help run in small batches. */
create table #UnusedBlobIDs (
ID UNIQUEIDENTIFIER PRIMARY KEY (ID)
);
WITH [ExistingBlobs] ([BlobId]) AS (
SELECT [Blobs].[BlobId]
FROM [Blobs]
JOIN [SharedFields]
@michaellwest
michaellwest / Config_Enable-Disable_Sitecore_8.1_upd3.csv
Last active June 20, 2024 12:45
The following script imports the specified Sitecore Role configuration csv and automatically enables or disables the configs.
Product Filepath Filename DefaultExtension Provider CD CM PRC CMP RPT
Platform \website\ Web.config config Enable Enable Enable Enable Enable
Platform \website\App_Config\ Commands.config config Enable Enable Enable Enable Enable
Platform \website\App_Config\ ConnectionStrings.config config Enable Enable Enable Enable Enable
Platform \website\App_Config\ ConnectionStringsOracle.config config Enable Enable Enable Enable Enable
Platform \website\App_Config\ FieldTypes.config config Enable Enable Enable Enable Enable
Platform \website\App_Config\ Icons.config config Enable Enable Enable Enable Enable
Platform \website\App_Config\ LanguageDefinitions.config config Enable Enable Enable Enable Enable
Platform \website\App_Config\ MimeTypes.config config Enable Enable Enable Enable Enable
Platform \website\App_Config\ Portraits.config config Enable Enable Enable Enable Enable
@michaellwest
michaellwest / ImportWizardFromCSV.ps1
Last active June 4, 2024 19:13
Import content from a CSV using Sitecore PowerShell Extensions.
<#
.SYNOPSIS
Data Import Wizard provides a way to generate or update content from an external file.
.DESCRIPTION
The import file uses the properties "Name" and "Id" to help match existing items.
.NOTES
Requires Sitecore PowerShell Extensions 4.6 or newer.
@michaellwest
michaellwest / FindRevisionIssues.ps1
Last active May 2, 2024 14:17
Sitecore PowerShell Extensions script to rename items. Workaround for an issue in SXA where items are not published because the revision is missing on the item (even though the Content Editor shows one). Sitecore Support public reference number 522438
$matchedItems = [System.Collections.ArrayList]@()
$revisionFilter = @("9323dec0-9b37-4fae-b87c-2dc12cbea0f2")
Get-ChildItem -Path "master:\media library" -Recurse |
Where-Object { [string]::IsNullOrEmpty($PSItem["__revision"]) -or $revisionFilter -contains $PSItem["__revision"] } |
ForEach-Object { $matchedItems.Add([PSCustomObject]@{"ItemId"=$PSItem.ID; "RevisionId"=$PSItem["__revision"]; "ItemPath"=$PSItem.ItemPath}) > $null }
$matchedItems | Show-ListView
@michaellwest
michaellwest / Get-ItemUrl.ps1
Created February 13, 2019 21:34
Generate an item url given an item and the sitecontext using Sitecore PowerShell Extensions.
function Get-ItemUrl {
param(
[item]$Item,
[Sitecore.Sites.SiteContext]$SiteContext
)
$result = New-UsingBlock(New-Object Sitecore.Sites.SiteContextSwitcher $siteContext) {
New-UsingBlock(New-Object Sitecore.Data.DatabaseSwitcher $item.Database) {
[Sitecore.Links.LinkManager]::GetItemUrl($item)
}