Skip to content

Instantly share code, notes, and snippets.

@michaellwest
michaellwest / UpdateExternalLink.ps1
Last active April 13, 2020 18:25
Update external links to open in a new tab using Sitecore PowerShell Extensions.
@michaellwest
michaellwest / CleanupTickets.ps1
Last active April 27, 2020 01:44
Remove SC_TICKET entries from the Core database using Sitecore PowerShell Extensions.
<#
.SYNOPSIS
There is an issue with the authentication ticket cleanup for certain versions of Sitecore. Run this script as a scheduled task.
.LINK
https://kb.sitecore.net/articles/615926
$ticketIds = [Sitecore.Web.Authentication.TicketManager]::GetTicketIDs() |
ForEach-Object { $_.Replace("_", "") }
@michaellwest
michaellwest / FindItemsWithSpecialCharacter.ps1
Last active March 30, 2020 19:47
Finds items in the database with a special character using Sitecore PowerShell Extensions.
Import-Function -Name Invoke-SqlCommand
$connection = [Sitecore.Configuration.Settings]::GetConnectionString("master")
$text = '%' + 'Ã' + '%'
$query = @"
select [ItemID], [FieldID], LEN([Value]) AS [FieldLength] from [SharedFields] WITH (NOLOCK) where [Value] like @0
"@
$shared = Invoke-SqlCommand -Connection $connection -Query $query -Parameters @{"@0"=$text}
$query = @"
@michaellwest
michaellwest / Validate-GeneralLink.ps1
Created March 20, 2020 18:22
Validate the xml stored in a GeneralLink field using Sitecore PowerShell Extensions.
@michaellwest
michaellwest / RSAKeyTools.ps1
Last active January 6, 2020 17:07
Convert the certificate private key to a PKCS8 formatted file. Made use of this for Traefik.
<#
.SYNPOSIS
Convert a PrivateKey from the certificate store into a PKCS8 formatted file.
.LINK
Found C# version here https://gist.github.com/chenrui1988/6b104a010172786dbcbc0aafc466d291/
.NOTES
Michael West
#>
@michaellwest
michaellwest / FindLockedItemsInTheDatabase-Report.ps1
Last active October 22, 2019 19:07
Find locked items by user using Sitecore PowerShell Extensions. This takes into account which language and version of the items are locked.
<#
.SYNOPSIS
Lists all the items locked by the specified user.
.NOTES
Adam Najmanowicz, Michael West
#>
Import-Function -Name Invoke-SqlCommand
@michaellwest
michaellwest / SharePoint-AddSelectAll
Created September 25, 2019 22:04
Adds a select all option to a SharePoint list of checkboxes.
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.js" integrity="sha256-WpOohJOqMqqyKL9FccASB9O0KwACQJpFTUBLTYOVvVU=" crossorigin="anonymous"></script>
<script type="text/javascript">
$(function() {
var statesTable = $('table[id^="State"');
var selectAll = $('<a href="#" id="select-all-states">Select All</a>').insertBefore(statesTable);
selectAll.on('click', function(e) {
e.preventDefault();
statesTable.find('.ms-RadioText :checkbox').prop('checked', true);
});
$('<span>&nbsp;</span>').insertBefore(statesTable);
@michaellwest
michaellwest / CleanupBlobData.sql
Created September 24, 2019 16:03
Cleanup orphaned blob data using SSMS. When Sitecore runs this process it may timeout otherwise.
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 / SitecoreRenderingStats.ps1
Created September 10, 2019 19:12
Duplicates the functionality seen in the Sitecore stats.aspx admin page using Sitecore PowerShell Extensions.
$items = [Sitecore.Diagnostics.Statistics]::RenderingStatistics
$props = @{
Property = @(
@{Label="Rendering"; Expression={$_.TraceName} },
@{Label="Site"; Expression={$_.SiteName} },
@{Label="Count"; Expression={$_.RenderCount} },
@{Label="From cache"; Expression={$_.UsedCache} },
@{Label="Avg. time (ms)"; Expression={$_.AverageTime.TotalMilliseconds} },
@{Label="Avg. items"; Expression={$_.AverageItemsAccessed} },
@{Label="Max. time"; Expression={$_.MaxTime.TotalMilliseconds} },
@michaellwest
michaellwest / Remove-Multiple-Sessions.ps1
Created July 15, 2019 18:53
Remove duplicate user sessions during login using Sitecore PowerShell Extensions. Solution for https://github.com/SitecoreSupport/Sitecore.Support.94909.
# Solution for https://github.com/SitecoreSupport/Sitecore.Support.94909
# Cannot login in Sitecore CMS due to multiple same users already logged in
# Saved to /sitecore/system/Modules/PowerShell/Script Library/[CUSTOM_MODULE_NAME]/Pipelines/LoggedIn/Remove Multiple Sessions
$pipelineArgs = Get-Variable -Name pipelineArgs -ValueOnly
$username = $pipelineArgs.UserName
if(!$username) { return }
$sessionId = [System.Web.HttpContext]::Current.Session.SessionID
Write-Log "The current session Id is $($sessionId) for user $($username)"