This command retrieves and compares the date/time for the last known good DBCC CHECKDB, as well as the creation date/time for the database.
This function supports SQL Server 2005+
Please note that this script uses the DBCC DBINFO() WITH TABLERESULTS. DBCC DBINFO has several known weak points, such as:
– DBCC DBINFO is an undocumented feature/command.
– The LastKnowGood timestamp is updated when a DBCC CHECKFILEGROUP is performed.
– The LastKnowGood timestamp is updated when a DBCC CHECKDB WITH PHYSICAL_ONLY is performed.
– The LastKnowGood timestamp does not get updated when a database in READ_ONLY.
An empty ($null) LastGoodCheckDb result indicates that a good DBCC CHECKDB has never been performed.
Get-DbaLastGoodCheckDb -SqlServer ServerA\sql987
Returns a custom object with Server name, Database name, and the date the last time a good checkdb was performed
Get-DbaLastGoodCheckDb -SqlServer ServerA\sql987 -Detailed | Format-Table -AutoSize
Returns a formatted table displaying Server, Database, DatabaseCreated, LastGoodCheckDb, DaysSinceDbCreated, DaysSinceLastGoodCheckDb, Status and DataPurityEnabled