Skip to content

Instantly share code, notes, and snippets.

@michaellwest
michaellwest / Find Fragmented Tables.sql
Last active Aug 8, 2022
SQL Maintenance Scripts for Sitecore
View Find Fragmented Tables.sql
-- 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
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
View FindRevisionIssues.ps1
$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 Aug 18, 2021
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.
View .gitlab-ci.yml
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 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 / 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 / ScanNavigationLinks.ps1
Created Feb 27, 2021
Find how many links will be queried when using the SXA Navigation component with a Sitecore PowerShell Extensions script.
View ScanNavigationLinks.ps1
@michaellwest
michaellwest / CleanupFields.sql
Last active Oct 19, 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 / ScopeQueryToSearchStringModels.ps1
Last active Dec 6, 2020
Convert ScopeQuery to SearchStringModels using Sitecore PowerShell Extensions.
View ScopeQueryToSearchStringModels.ps1
#$provider = [Sitecore.DependencyInjection.ServiceLocator]::ServiceProvider.GetService([Sitecore.XA.Foundation.Abstractions.Configuration.IConfiguration[Sitecore.XA.Foundation.Search.SearchConfiguration]]).GetConfiguration().QueryMaxItems
$query = "+template:{51ed5851-1a61-4dae-b803-6c7fae6b43d8};+sxa:SameFirstTagAsCurrentPage|SxaTags;custom:EventStartDate|[NOW TO *];custom:EventEndDate|[NOW TO *];sort:eventstartdate;sort:isfeatured[desc]"
$modelList = [Sitecore.ContentSearch.Utilities.SearchStringModel]::ParseDatasourceString($query)
$contextItem = Get-Item -Path "master:" -ID "{31318AEE-310B-4EE4-84DA-4B84471E0FCA}"
[Sitecore.DependencyInjection.ServiceLocator]::ServiceProvider.GetService([Sitecore.XA.Foundation.Search.Services.ISearchQueryTokenResolver]).Resolve($modelList, $contextItem)
class CustomSearchResultItem : SearchResultItem
{
[Sitecore.ContentSearch.IndexField("eventstartdate_tdt")]
@michaellwest
michaellwest / ReportAndRemoveBustedLanguageFields.ps1
Last active Oct 22, 2020
Find and delete fields where the language is empty using Sitecore PowerShell Extensions.
View ReportAndRemoveBustedLanguageFields.ps1
$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 / CompareTwoIndexes.ps1
Last active Oct 22, 2020
Compare two indexes using Sitecore PowerShell Extensions to see what's missing.
View CompareTwoIndexes.ps1
# This is a ScopeQuery item found in SXA. You don't have to use this.
$scopeItem = Get-Item -Path "master:" -ID "{648F4C3A-C9EA-4FCF-82A3-39ED2AC90A06}"
# If not using SXA, you can replace this with the string from the QueryBuilder field type.
$scopeQuery = $scopeItem.ScopeQuery
$props = @{
Index = "sitecore_sxa_master_index"
ScopeQuery = $scopeQuery
}
$referenceList = Find-Item @props