Forked from michaellwest/QueryCleanupQueueCounts.sql
Created
September 7, 2019 22:31
-
-
Save suryagahlot/2d277400a192778c7c429fa85aef30f1 to your computer and use it in GitHub Desktop.
Queries the queue tables and counts the number of records 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
$sql = @" | |
USE {0} | |
SELECT COUNT(*) FROM [SCSitecore_Master].[dbo].[EventQueue] | |
SELECT COUNT(*) FROM [SCSitecore_Master].[dbo].[PublishQueue] | |
SELECT COUNT(*) FROM [SCSitecore_Master].[dbo].[History] | |
"@ | |
Import-Function Invoke-SqlCommand | |
foreach($db in Get-Database | Where-Object {"filesystem" -notcontains $_ }) { | |
Write-Verbose "Cleaning up the History, EventQueue, and PublishQueue tables in the $($db.Name) database." | |
$connection = [Sitecore.Configuration.Settings]::GetConnectionString($db.Name) | |
$builder = New-Object System.Data.SqlClient.SqlConnectionStringBuilder $connection | |
$dbName = $builder.InitialCatalog | |
$query = [string]::Format($sql, $dbName) | |
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