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)
	{
	#dbi_dbccLastKnownGood
	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

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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

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