Skip to content

Instantly share code, notes, and snippets.

@michaellwest
michaellwest / Relink Sitecore Image.ps1
Last active Aug 3, 2021
Demonstrates how to relink images using Sitecore PowerShell Extensions. Comment included by Dylan shows how to Remove the link and remove the item.
View Relink Sitecore Image.ps1
@michaellwest
michaellwest / SharePoint-HighlightRows.js
Last active Jun 22, 2021
Highlight rows in a SharePoint list.
View SharePoint-HighlightRows.js
<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 / UnusedMediaItems.ps1
Last active May 24, 2021
Sitecore PowerShell script to locate media items without reference to any other item.
View UnusedMediaItems.ps1
<#
.SYNOPSIS
Lists all media items that are not linked to other items.
.NOTES
Michael West
#>
# HasReference determines if the specified item is referenced by any other item.
function HasReference {
@michaellwest
michaellwest / SortIPsByCount.ps1
Created May 14, 2021
Sort a list of IP addresses by count and IP.
View SortIPsByCount.ps1
$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"
@michaellwest
michaellwest / ImportWizardFromCSV.ps1
Last active May 5, 2021
Import content from a CSV using Sitecore PowerShell Extensions.
View ImportWizardFromCSV.ps1
<#
.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 / CleanupFields.sql
Last active Mar 10, 2021
Scripts for use with cleaning up Sitecore tables.
View CleanupFields.sql
-- Find field data not associated with an item.
SELECT Id FROM SharedFields f
WHERE NOT EXISTS (SELECT ID FROM Items i WHERE i.ID = f.ItemId)
SELECT Id FROM UnversionedFields f
WHERE NOT EXISTS (SELECT ID FROM Items i WHERE i.ID = f.ItemId)
SELECT Id FROM VersionedFields f
WHERE NOT EXISTS (SELECT ID FROM Items i WHERE i.ID = f.ItemId)
@michaellwest
michaellwest / CleanupBlobData.sql
Created Sep 24, 2019
Cleanup orphaned blob data using SSMS. When Sitecore runs this process it may timeout otherwise.
View CleanupBlobData.sql
DECLARE @BlobID uniqueidentifier;
SELECT @BlobID = '{FF8A2D01-8A77-4F1B-A966-65806993CD31}';
WITH [BlobFields] ([fieldid])
AS (SELECT [sharedfields].[itemid]
FROM [sharedfields]
WHERE [sharedfields].[fieldid] = @BlobID
AND [sharedfields].[value] = 1
UNION
SELECT [versionedfields].[itemid]
@michaellwest
michaellwest / Spe.ShieldsDown.config
Created Aug 19, 2020
Example to turn off some of the security features for local development with Sitecore PowerShell Extensions. https://alan-null.github.io/2017/01/spe-dev-config
View Spe.ShieldsDown.config
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<powershell>
<services>
<remoting>
<patch:attribute name="enabled">true</patch:attribute>
<authorization>
<add Permission="Allow" IdentityType="User" Identity="sitecore\admin" />
</authorization>
</remoting>
@michaellwest
michaellwest / DeleteFromPublishingJobQueue.ps1
Last active Mar 10, 2021
Remove entries in the Sitecore Publishing Service queue using PowerShell.
View DeleteFromPublishingJobQueue.ps1
Import-Function -Name Invoke-SqlCommand
$connection = [Sitecore.Configuration.Settings]::GetConnectionString("master")
$query = @"
DELETE TOP (1000)
FROM [dbo].[Publishing_JobQueue]
SELECT COUNT(*) QueueCount
FROM [dbo].[Publishing_JobQueue]
"@
@michaellwest
michaellwest / SPE-Dialog-With-Commands.ps1
Created Oct 7, 2018
Displays a dialog using Sitecore PowerShell Extensions.
View SPE-Dialog-With-Commands.ps1
# Be sure to update this ID to whichever script you want to execute when the link is clicked.
$scriptId = "{6EAF681D-5D87-4C43-B279-356A8B9A15CF}"
$item = Get-Item -Path "."
$script = Get-Item -Path "master:" -ID $scriptId
$command = "item:executescript(id=$($item.ID),db=$($item.Database.Name),script=$($script.ID),scriptDb=$($script.Database.Name))"
$options = [ordered]@{"Download Sample"=$command;"View Documentation"=$command;}
$props = @{
Parameters = @(