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 / 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 / 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]
<?xml version="1.0" encoding="UTF-8"?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<log4net>
<!-- Add a StringMatchFilter into the LogFileAppender -->
<appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender, Sitecore.Logging">
<filter type="log4net.Filter.StringMatchFilter">
<stringToMatch value="Results endpoint exception" />
<acceptOnMatch value="false" />
</filter>
@michaellwest
michaellwest / ReserializeItems.ps1
Created February 17, 2023 15:44
Reserialize Unicorm items using Sitecore PowerShell Extensions. Useful when fields are missing and need to be regenerated.
$lines = @"
/sitecore/content/home
"@
$paths = $lines.Split([Environment]::NewLine, [StringSplitOptions]::RemoveEmptyEntries)
foreach($path in $paths) {
Get-Item -Path ($path.Replace("/sitecore", "master:")) | Export-UnicornItem
}
@michaellwest
michaellwest / ContentMigratorAllSites.ps1
Created February 15, 2023 19:33
Sitecore PowerShell Extensions Content Migrator for all sites using SXA Get-AllSxaSite.
Clear-Host
Import-Module -Name SPE -Force
$scriptDirectory = & {
if ($psISE) {
Split-Path -Path $psISE.CurrentFile.FullPath
} else {
$PSScriptRoot
}
@michaellwest
michaellwest / IAR.101.config
Created February 7, 2023 01:16
Sample configuration for Sitecore 10.1 using IAR. Adds an additional location that is later included by default in 10.2.
<?xml version="1.0" encoding="utf-8" ?>
<!--
Purpose: Adds in an additional location to load IAR files from
This config can be removed if the project is upgraded to 10.2+ since the path is set ootb
-->
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:role="http://www.sitecore.net/xmlconfig/role/">
<sitecore>
<databases>
<database id="master" role:require="Standalone or ContentManagement">
<dataProviders>
@michaellwest
michaellwest / ExceptionMessage.txt
Last active January 31, 2023 20:38
Issues related to a LetsEncrypt certificate unable to validate against the Certificate Revocation List (CRL).
Exception: System.Security.Authentication.AuthenticationException
Message: The remote certificate is invalid according to the validation procedure.
Source: System
at System.Net.Security.SslState.StartSendAuthResetSignal(ProtocolToken message, AsyncProtocolRequest asyncRequest, Exception exception)
at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
@michaellwest
michaellwest / CheckCertRevocation.ps1
Last active January 31, 2023 17:46
Check certificate revocation using PowerShell.
# Potential workaround for errors:
# https://stackoverflow.com/questions/2675133/c-sharp-ignore-certificate-errors
# https://stackoverflow.com/a/66882479/1277533
$webRequest = [Net.WebRequest]::Create("https://www.company.com")
try { $webRequest.GetResponse() } catch {}
$cert = $webRequest.ServicePoint.Certificate
#$bytes = $cert.Export([Security.Cryptography.X509Certificates.X509ContentType]::Cert)
#set-content -value $bytes -encoding byte -path "$pwd\company.cer"
#certutil.exe -verify -urlfetch "$pwd\company.cer"