Skip to content

Instantly share code, notes, and snippets.

@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).
View ExceptionMessage.txt
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.
View CheckCertRevocation.ps1
# 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"
@michaellwest
michaellwest / inspect.ps1
Last active January 22, 2023 04:36
List Docker Container Name and IPAddress as a table using PowerShell.
View inspect.ps1
docker ps -q | ForEach-Object { "Name,IPAddress" } { $data = docker inspect $_ --format '{{json .Name}},{{range .NetworkSettings.Networks}}{{json .IPAddress}}{{end}}'; $data.replace('/','') } | ConvertFrom-Csv
<#
Name IPAddress
---- ---------
spe-traefik-1 172.31.127.71
spe-cm-1 172.31.126.246
spe-id-1 172.31.116.201
spe-mssql-1 172.31.120.96
spe-solr-1 172.31.121.74
@michaellwest
michaellwest / SplunkQuery.txt
Last active January 18, 2023 19:52
Split query string data into table format with Splunk.
View SplunkQuery.txt
index=iis sourcetype=ms:iis:auto NOT cs_uri_stem="/sitecore/service/keepalive.aspx" NOT cs_User_Agent="*PRTG+Network+Monitor*" cs_uri_stem="/sxa/search/results*" | rex field=cs_uri_query max_match=0 "[\&]?(?<qkey>[^=]+)=(?<qvalue>[^&]+)?"
| eval fields = mvzip(qkey,qvalue)
| mvexpand fields
| eval pairs=split(fields,",")
| eval key=mvindex(pairs,0), value=mvindex(pairs,1)
| fields cs_host cs_uri_query a g q
| eval a=urldecode(a)
| eval g=urldecode(g)
| eval q=urldecode(q)
| stats values(*) as * by cs_uri_query
@michaellwest
michaellwest / CurlCMError.ps1
Created January 16, 2023 21:01
Curl the home page when the CM reports unhealthy. For use with Sitecore and Docker.
View CurlCMError.ps1
$containers = docker ps -a --format "table {{.Names}}"
$container = $containers | ConvertFrom-Csv | Where-Object { $_.NAMES -match "-cm" } | Select-Object -First 1 -ExpandProperty NAMES
docker exec $container curl http://cm
@michaellwest
michaellwest / DatabaseMissing.yml
Last active January 16, 2023 19:26
Sample content for michaellwest.blogspot.com post.
View DatabaseMissing.yml
---
ID: "9c7e7d60-bfa0-4fec-b55c-462b3efdd545"
Parent: "839b77db-6040-4f00-8771-8e96fd37aba2"
Template: "854ba861-63ea-4a0c-8c7b-541e9a7ec4c1"
Path: /sitecore/system/Settings/Foundation/Scms/Search/Search Query Rules Context/Tags/Default
DB: master
@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.
View ResolveUser.cs
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 December 16, 2022 19:22
A convenient PowerShell script to list all the docker images and pull the from the registry.
View PullAllDockerImages.ps1
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.
View FindItemsWithRules.ps1
<#
.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.
View CompareFieldChanges.ps1
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