Last active
April 27, 2020 01:44
-
-
Save michaellwest/3b772666b1a454d8caebd5df15585042 to your computer and use it in GitHub Desktop.
Remove SC_TICKET entries from the Core database using Sitecore PowerShell Extensions.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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