Find Servers with large sysjobhistory tables

This script will return you a list of servers with the rowcount of sysjobhistory >=500.  Much like the previous post, used for finding servers that have no history cleanup jobs.  You will need SQLPSX installed to run this.

cls
$servers = Get-Content c:\Test\Servers.txt
$countThreshold = 500

foreach($server in $servers)
{
	$rows = Get-SqlData -dbname msdb -sqlserver $server -qry "SELECT COUNT(*) AS HistCount FROM dbo.sysjobhistory" #| Format-Table -AutoSize
	$nRowCount = [int]$rows[0]
	if($nRowCount -ge $countThreshold)
	{
		Write-Host "Server $server has a rowcount of $nRowCount in sysjobhistory.  There is probably no history cleanup job on this server."
	}
}


Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.