Skip to content

Instantly share code, notes, and snippets.

@michaellwest
Last active April 27, 2020 01:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michaellwest/3b772666b1a454d8caebd5df15585042 to your computer and use it in GitHub Desktop.
Save michaellwest/3b772666b1a454d8caebd5df15585042 to your computer and use it in GitHub Desktop.
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("_", "") }
$countRemoved = 0
[Sitecore.Diagnostics.Log]::Info("CleanupAuthenticationTicketsScript: Total number of authentication tickets to process: $($ticketIds.Count)", $host)
foreach($ticketId in $ticketIds) {
$ticket = [Sitecore.Web.Authentication.TicketManager]::GetTicket($ticketId, $true)
if($ticket) {
if([Sitecore.Web.Authentication.TicketManager]::IsTicketExpired($ticket, $false)) {
[Sitecore.Web.Authentication.TicketManager]::RemoveTicket($ticket.Id) > $null
$countRemoved++
}
}
}
[Sitecore.Diagnostics.Log]::Info("CleanupAuthenticationTicketsScript: Number of expired authentication tickets that have been removed: $($countRemoved)", $host)
# https://kb.sitecore.net/articles/345947
# https://kb.sitecore.net/articles/615926
Import-Function -Name Invoke-SqlCommand
$connection = [Sitecore.Configuration.Settings]::GetConnectionString("core")
$query = @"
DELETE TOP (100)
FROM [dbo].[Properties]
WHERE [Key] LIKE 'SC_TICKET_%'
"@
$records = Invoke-SqlCommand -Connection $connection -Query $query
$query = @"
SELECT COUNT(*)
FROM [dbo].[Properties]
--WHERE [Key] LIKE 'SC_TICKET_%'
"@
$count = Invoke-SqlCommand -Connection $connection -Query $query -As Scalar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment