Skip to content

Instantly share code, notes, and snippets.

@michaellwest
michaellwest / MovingAverage.ps1
Created July 11, 2020 01:40
A calculator to return the average of the last number of x items. This can be useful when you want to estimate time remaining.
# Converted from this answer: https://stackoverflow.com/a/44318312/1277533
class AverageCalculator {
[System.Collections.Queue]$Queue
[long]$Total
[int]$Size
AverageCalculator([int]$Size) {
$this.Queue = New-Object System.Collections.Queue
$this.Size = [Math]::Max($Size, 1)
Audit my Claude Skills (~/.claude/skills/*/SKILL.md and any project skills) on
five dimensions. For each skill, return: current state -> recommended change ->
one-line why. End with a consolidated changelog grouped by skill.
1. INVOCATION CONTROL (frontmatter)
Reference: https://code.claude.com/docs/en/skills.md#frontmatter-reference
- Skills with side effects (deploy, commit, push, send-message, post-to-slack,
delete, force-push): add `disable-model-invocation: true` so Claude can't
auto-fire them. User runs them deliberately with /name.
@michaellwest
michaellwest / CLAUDE.md
Created April 8, 2026 15:00
Global CLAUDE.md

Project Structure

This workspace contains multiple repositories under C:\Projects\github\sitecorepowershell\:

  • Book/ — Sitecore PowerShell Extensions book/documentation (SitecorePowerShell/Book)
  • mcp-server/ — MCP server for Sitecore PowerShell (SitecorePowerShell/mcp-server)
  • sitecorepowershell.com/ — Project website (SitecorePowerShell/sitecorepowershell.com)
  • Spe/ — Sitecore PowerShell Extensions module (SitecorePowerShell/Console)
  • tutorials/ — Tutorials (SitecorePowerShell/tutorials)

Execution Rule: Always confirm the active repository/project directory before executing searches or making file changes.

@michaellwest
michaellwest / Merge-XdtTransform.ps1
Last active March 3, 2026 00:45
Pure PowerShell script to apply an XDT transform with a typicaly web.config found in ASP.Net.
function Get-XdtNodeXPath {
param([System.Xml.XmlNode]$Node)
$parts = @($Node.LocalName)
$current = $Node
while ($current.ParentNode -and $current.ParentNode.NodeType -ne [System.Xml.XmlNodeType]::Document) {
$current = $current.ParentNode
$parts = @($current.LocalName) + $parts
}
return "/" + ($parts -join "/")
}
@michaellwest
michaellwest / dialog-builder-functions.md
Created December 21, 2025 01:55
Sitecore PowerShell Extensions dialog helper library. Simplifies the use of Read-Variable.
description Helper functions to simplify and optimize Read-Variable dialog creation.

Dialog Builder Functions

Overview

The Read-Variable cmdlet is powerful but requires verbose hashtable construction and manual variable initialization. These helper functions provide a fluent, intuitive API for building dialogs while handling the nuances of variable management automatically.

@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 / 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]