Skip to content

Instantly share code, notes, and snippets.

@michaellwest
Last active July 21, 2020 15:38
Show Gist options
  • Save michaellwest/fe9ea0a880c82dbea6476f6453165e52 to your computer and use it in GitHub Desktop.
Save michaellwest/fe9ea0a880c82dbea6476f6453165e52 to your computer and use it in GitHub Desktop.
Queries the queue tables and counts the number of records using Sitecore PowerShell Extensions.
$sql = @"
USE {0}
SELECT COUNT(*) FROM [dbo].[EventQueue]
SELECT COUNT(*) FROM [dbo].[PublishQueue]
SELECT COUNT(*) FROM [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