Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@michaellwest
michaellwest / CleanupTables.sql
Last active February 12, 2024 01:27
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 / 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)
}
@michaellwest
michaellwest / ReadExif.ps1
Created May 16, 2020 03:59
Read EXIF orientation using Sitecore PowerShell Extensions.
# https://exiftool.org/TagNames/EXIF.html
# https://stackoverflow.com/questions/27835064/get-image-orientation-and-rotate-as-per-orientation
# http://fredericiana.com/2013/05/23/imagetwist-exif-rotation-addon/
# https://www.cyotek.com/blog/handling-the-orientation-exif-tag-in-images-using-csharp
enum ExifOrientation {
RotateNoneFlipNone = 1
Rotate90FlipX = 5
Rotate90FlipNone = 6
}
#[System.Drawing.RotateFlipType]::Rotate90FlipNone
@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 / 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",
<?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 / Config_Enable-Disable_Sitecore_8.1_upd3.csv
Last active May 9, 2023 15:29
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 April 5, 2023 09:03
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 / ReportAndRemoveBustedLanguageFields.ps1
Last active April 5, 2023 09:02
Find and delete fields where the language is empty using Sitecore PowerShell Extensions.
$sql = @"
SELECT DISTINCT i.* FROM [dbo].[Items] i
INNER JOIN [dbo].[VersionedFields] v
ON i.ID = v.ItemId
WHERE v.[Language] = ''
--SELECT COUNT(*) AS COUNT FROM [VersionedFields] WHERE [Language] = ''
--DELETE FROM [VersionedFields] WHERE [Language] = ''
"@
@michaellwest
michaellwest / FindExifRotation.ps1
Last active February 20, 2023 19:15
Get the blob stream of a media item using Sitecore PowerShell Extensions.
$exifOrientationId = 0x112
if(!$items) {
$items = Get-ChildItem -Path "master:" -ID "{5D50B0FD-AB2B-4872-88E5-463D6E2B31F2}" -Recurse | Where-Object { $_.TemplateId -eq "{DAF085E8-602E-43A6-8299-038FF171349F}" }
}
$records = [System.Collections.ArrayList]@()
$processedCounter = 0
$totalCounter = $items.Count
foreach($item in $items) {
$processedCounter++