DMO to Check if Database is Suspect

One of the emails I received whilst on leave was asking if it is possible to check if a database has been marked suspect using SQLDMO.  Below is a VBScript snippet of how the database status can be checked to determine if the database has been marked suspect or not:

~~~

Dim oSQLServer

Set oSQLServer = CreateObject(“SQLDMO.SQLServer”)

oSQLServer.LoginSecure = True
oSQLServer.Connect “(local)”

If oSQLServer.Databases(“foo”).Status AND 256 = 256 Then
MsgbOx “The foo database is marked as suspect”
End If

oSQLServer.Disconnect
Set oSQLServer = Nothing

~~~