Skip to content

Instantly share code, notes, and snippets.

@michaellwest
michaellwest / ResolveUser.cs
Created November 29, 2022 19:38
Replace the Sitecore 10.2.1 cumulative hotfix implementation with what was originally provided in 10.2.0.
using Microsoft.AspNet.Identity;
using Sitecore.Diagnostics;
using Sitecore.Owin.Authentication.Extensions;
using Sitecore.Owin.Authentication.Pipelines.CookieAuthentication.SignIn;
using Sitecore.Owin.Authentication.Services;
using Sitecore.Security.Accounts;
using System.Security.Claims;
namespace Scms.Feature.Security.Pipelines.CookieAuthentication.SignIn
{
@michaellwest
michaellwest / PullAllDockerImages.ps1
Last active September 1, 2023 01:28
A convenient PowerShell script to list all the docker images and pull the from the registry.
docker image ls --format "{{json .Repository}},{{json .Tag}},{{json .ID}}" |
ConvertFrom-Csv -Header "Repository","Tag","Id" |
Where-Object { $_.Tag -ne "<none>" -and $_.Repository.Contains("/") } |
ForEach-Object { docker pull "$($_.Repository):$($_.Tag)"}
@michaellwest
michaellwest / FindItemsWithRules.ps1
Created September 23, 2022 03:24
Sitecore PowerShell Extensions report to find all script and script library items containing either a ShowRule or EnableRule.
<#
.SYNOPSIS
Report all the PowerShell Script (Library) items which contain a ShowRule or EnableRule
.NOTES
Michael West
#>
$items = Get-ChildItem -Path "master:" -ID "{A3572733-5062-43E9-A447-54698BC1C637}" -Recurse | Where-Object { ($_.ShowRule -and $_.ShowRule -ne "<ruleset />") -or ($_.EnableRule -and $_.EnableRule -ne "<ruleset />") }
@michaellwest
michaellwest / CompareFieldChanges.ps1
Last active February 3, 2023 15:18
The following Sitecore PowerShell Extensions script finds items stored in the IAR files that also exist in the database.
function Get-ModifiedItem {
param(
$databaseName,
$filename
)
$resourceLoaderType = ([System.Type]::GetType("Sitecore.Data.DataProviders.ReadOnly.Protobuf.IResourceLoader, Sitecore.Data.ResourceItems.ProtobufNet"))
$resourceLoader = [Sitecore.DependencyInjection.ServiceLocator]::ServiceProvider.GetService($resourceLoaderType)
$paths = [System.Collections.Generic.List[String]]@()
$paths.Add([Sitecore.MainUtil]::MapPath("/App_Data/items/$($databaseName)/$($filename)")) > $null
@michaellwest
michaellwest / HangfireRecurringJobs.ps1
Last active July 26, 2023 14:59
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 / Find Fragmented Tables.sql
Last active August 8, 2022 13:31
SQL Maintenance Scripts for Sitecore
-- https://www.sqlshack.com/how-to-identify-and-resolve-sql-server-index-fragmentation/
SELECT S.name as 'Schema',
T.name as 'Table',
I.name as 'Index',
DDIPS.avg_fragmentation_in_percent,
DDIPS.page_count
FROM sys.dm_db_index_physical_stats (DB_ID(), NULL, NULL, NULL, NULL) AS DDIPS
INNER JOIN sys.tables T on T.object_id = DDIPS.object_id
INNER JOIN sys.schemas S on T.schema_id = S.schema_id
INNER JOIN sys.indexes I ON I.object_id = DDIPS.object_id
@michaellwest
michaellwest / FindRevisionIssues.ps1
Last active May 12, 2022 01:55
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 / .gitlab-ci.yml
Last active August 18, 2021 15:02
Example using GitLab to build a custom .net 5.0 SDK image using kaniko. We use kaniko to build the container in runtime this makes it so the building doesn’t require access to the docker daemon. This allows to utilize the normal runners and don’t have to enable privileged mode in docker.
stages:
- build:dotnet
default:
image:
name: gcr.io/kaniko-project/executor:debug
entrypoint: [""]
.job_template:
script: &script_definition
@michaellwest
michaellwest / SharePoint-HighlightRows.js
Last active June 22, 2021 17:32
Highlight rows in a SharePoint list.
<script src=https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js></script>
<script>
jQuery(function() {
function applyStyles() {
jQuery(".ms-listviewtable tbody tr td:nth-child(3):contains('Required')").parent().css('background-color','red');
jQuery(".ms-listviewtable tbody tr td:nth-child(3):contains('Conditionally Required')").parent().css('background-color','blue');
jQuery(".ms-listviewtable tbody tr td:nth-child(3):contains('Additional Services')").parent().css('background-color','yellow');
jQuery(".ms-listviewtable tbody[id*='titl'] > tr > td > span").remove()
}
applyStyles();
@michaellwest
michaellwest / SortIPsByCount.ps1
Created May 14, 2021 15:31
Sort a list of IP addresses by count and IP.
$ips = @(
"19.143.116.98"
"19.143.116.98"
"19.143.116.98"
"19.143.116.98"
"19.143.116.98"
"19.143.116.98"
"19.143.116.98"
"19.143.116.98"
"15.37.53.228"