Skip to content

February 11, 2013

Get Last DBCC CheckDB Date for all Databases

by Scott Newman

This will check for the last known checkdb date for all user databases.  This uses SqlPSX.

Import-Module SqlServer

$outputs = @();
$srv = Get-SqlServer -sqlserver "ServerName"
foreach($database in $srv.Databases | where{$_.IsSystemObject -eq $false})
	$query = "DBCC DBINFO ('$($database.Name)') WITH TABLERESULTS"
	$results = Get-SqlData -sqlserver $srv -dbname $database -qry $query
	foreach($datarow in $results)
	if($datarow.Field.ToString() -eq "dbi_dbccLastKnownGood")
		$output = New-Object -TypeName PSObject -Property @{
			Name = $database.Name
			DBCCDate = $datarow.VALUE.ToString()
		$outputs += $output
$outputs | Format-Table -AutoSize
Read more from Powershell, SQL Server

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Note: HTML is allowed. Your email address will never be published.

Subscribe to comments

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

%d bloggers like this: