DatabaseDiscovery

Microsoft.KnowledgeServices.SQLServer.Library.DatabaseDiscovery (Discovery)

Performs knowledge services database discovery.

Element properties:

TargetMicrosoft.SQLServer.DBEngine
EnabledTrue
RemotableFalse

Object Discovery Details:

Discovered Classes and their attribuets:
  • Microsoft.KnowledgeServices.SQLServer.Database
    • DatabaseId
    • PageVerify
    • Status
    • IsMirroringEnabled
    • MirroringRole
    • CreateDate
    • CompatibilityLevel
    • ReadOnly
    • AutoClose
    • AutoShrink
    • StandBy
    • CleanlyShutdown
    • SnapshotIsolationState
    • IsReadCommittedSnapshotOn
    • AutoCreateStatisticsEnabled
    • AutoUpdateStatisticsEnabled
    • AutoUpdateStatisticsAsync
    • AnsiNullDefault
    • AnsiNullsEnabled
    • AnsiPaddingEnabled
    • AnsiWarningsEnabled
    • ArithmeticAbortEnabled
    • ConcatenateNullYieldsNull
    • NumericRoundAbortEnabled
    • QuotedIdentifiersEnabled
    • RecursiveTriggersEnabled
    • CloseCursorsOnCommitEnabled
    • LocalCursorsDefault
    • IsFullTextEnabled
    • Trustworthy
    • DatabaseOwnershipChaining
    • IsParameterizationForced
    • IsMasterKeyEncryptedByServer
    • IsPublished
    • IsSubscribed
    • IsMergePublished
    • IsDistributor
    • IsSyncWithBackup
    • BrokerEnabled
    • LogReuseWaitStatus
    • DateCorrelationOptimization
    • IsCDCEnabled
    • EncryptionEnabled
    • HonorBrokerPriority
    • SupplementalLoggingEnabled
    • EngineModelCollation
    • IsSharepointDatabase
    • IsSSRSDatabase
    • IsSharepointSSRSSystemDatabase
    • SystemCatalogUpdated
    • TargetRecoveryTimeInSeconds
    • Containment
    • FiletableNonTransactedAccess
    • DataBaseGuid
    • FamilyGuid

Member Modules:

ID Module Type TypeId RunAs 
scheduledScriptDatabase DataSource Microsoft.KnowledgeServices.Library.ScheduledScriptDiscoveryEx Default

Source Code:

<Discovery ID="Microsoft.KnowledgeServices.SQLServer.Library.DatabaseDiscovery" Enabled="true" Target="SQL!Microsoft.SQLServer.DBEngine" ConfirmDelivery="false" Remotable="true" Priority="Normal">
<Category>Discovery</Category>
<DiscoveryTypes>
<DiscoveryClass TypeID="KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database">
<Property TypeID="KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database" PropertyID="DatabaseId"/>
<Property TypeID="KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database" PropertyID="PageVerify"/>
<Property TypeID="KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database" PropertyID="Status"/>
<Property TypeID="KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database" PropertyID="IsMirroringEnabled"/>
<Property TypeID="KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database" PropertyID="MirroringRole"/>
<Property TypeID="KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database" PropertyID="CreateDate"/>
<Property TypeID="KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database" PropertyID="CompatibilityLevel"/>
<Property TypeID="KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database" PropertyID="ReadOnly"/>
<Property TypeID="KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database" PropertyID="AutoClose"/>
<Property TypeID="KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database" PropertyID="AutoShrink"/>
<Property TypeID="KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database" PropertyID="StandBy"/>
<Property TypeID="KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database" PropertyID="CleanlyShutdown"/>
<Property TypeID="KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database" PropertyID="SnapshotIsolationState"/>
<Property TypeID="KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database" PropertyID="IsReadCommittedSnapshotOn"/>
<Property TypeID="KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database" PropertyID="AutoCreateStatisticsEnabled"/>
<Property TypeID="KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database" PropertyID="AutoUpdateStatisticsEnabled"/>
<Property TypeID="KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database" PropertyID="AutoUpdateStatisticsAsync"/>
<Property TypeID="KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database" PropertyID="AnsiNullDefault"/>
<Property TypeID="KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database" PropertyID="AnsiNullsEnabled"/>
<Property TypeID="KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database" PropertyID="AnsiPaddingEnabled"/>
<Property TypeID="KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database" PropertyID="AnsiWarningsEnabled"/>
<Property TypeID="KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database" PropertyID="ArithmeticAbortEnabled"/>
<Property TypeID="KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database" PropertyID="ConcatenateNullYieldsNull"/>
<Property TypeID="KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database" PropertyID="NumericRoundAbortEnabled"/>
<Property TypeID="KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database" PropertyID="QuotedIdentifiersEnabled"/>
<Property TypeID="KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database" PropertyID="RecursiveTriggersEnabled"/>
<Property TypeID="KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database" PropertyID="CloseCursorsOnCommitEnabled"/>
<Property TypeID="KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database" PropertyID="LocalCursorsDefault"/>
<Property TypeID="KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database" PropertyID="IsFullTextEnabled"/>
<Property TypeID="KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database" PropertyID="Trustworthy"/>
<Property TypeID="KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database" PropertyID="DatabaseOwnershipChaining"/>
<Property TypeID="KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database" PropertyID="IsParameterizationForced"/>
<Property TypeID="KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database" PropertyID="IsMasterKeyEncryptedByServer"/>
<Property TypeID="KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database" PropertyID="IsPublished"/>
<Property TypeID="KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database" PropertyID="IsSubscribed"/>
<Property TypeID="KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database" PropertyID="IsMergePublished"/>
<Property TypeID="KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database" PropertyID="IsDistributor"/>
<Property TypeID="KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database" PropertyID="IsSyncWithBackup"/>
<Property TypeID="KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database" PropertyID="BrokerEnabled"/>
<Property TypeID="KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database" PropertyID="LogReuseWaitStatus"/>
<Property TypeID="KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database" PropertyID="DateCorrelationOptimization"/>
<Property TypeID="KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database" PropertyID="IsCDCEnabled"/>
<Property TypeID="KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database" PropertyID="EncryptionEnabled"/>
<Property TypeID="KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database" PropertyID="HonorBrokerPriority"/>
<Property TypeID="KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database" PropertyID="SupplementalLoggingEnabled"/>
<Property TypeID="KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database" PropertyID="EngineModelCollation"/>
<Property TypeID="KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database" PropertyID="IsSharepointDatabase"/>
<Property TypeID="KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database" PropertyID="IsSSRSDatabase"/>
<Property TypeID="KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database" PropertyID="IsSharepointSSRSSystemDatabase"/>
<!--BEGIN : Edited by ericzha-->
<Property TypeID="KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database" PropertyID="SystemCatalogUpdated"/>
<Property TypeID="KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database" PropertyID="TargetRecoveryTimeInSeconds"/>
<Property TypeID="KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database" PropertyID="Containment"/>
<Property TypeID="KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database" PropertyID="FiletableNonTransactedAccess"/>
<!--END : Edited by ericzha-->
<!--BEGIN: Edited by v-jobzha-->
<Property TypeID="KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database" PropertyID="DataBaseGuid"/>
<Property TypeID="KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database" PropertyID="FamilyGuid"/>
<!--END: Edited by v-jobzha-->
</DiscoveryClass>
</DiscoveryTypes>
<DataSource ID="scheduledScriptDatabase" TypeID="KnowledgeServicesLibrary!Microsoft.KnowledgeServices.Library.ScheduledScriptDiscoveryEx">
<ScriptName>DiscoveryExtendedDBProperties.vbs</ScriptName>
<Arguments>$MPElement$ $Target/Id$ $Target/Host/Property[Type="Windows!Microsoft.Windows.Computer"]/PrincipalName$ $Target/Property[Type="SQL!Microsoft.SQLServer.ServerRole"]/InstanceName$ $Target/Property[Type="SQL!Microsoft.SQLServer.DBEngine"]/ConnectionString$</Arguments>
<ScriptBody><Script>
'#Include File:DiscoveryExtendedDBProperties.vbs

'Copyright (c) Microsoft Corporation. All rights reserved.
' Parameters that should be passed to this script
' Parameters that should be passed to this script
' 0 MPElement ID ($MPElement$)
' 1 Target Id for ME this rule is running against ($Target/Id$)
' 2 Computer FQDN
' 3 SQL Instance that this rule is being run for
' 4 The Data Source property in OLEDB connection string. (The connection string from DBEngine instance)

Option Explicit
SetLocale("en-us")

Dim scriptStartTime
scriptStartTime = GetUTCNow()

Dim oArgs
Set oArgs = WScript.Arguments
If oArgs.Count &lt;&gt; 5 Then
Wscript.Quit -1
End If

Dim SourceID, ManagedEntityId, TargetComputer, InstanceName, DataSource, TargetComputerID, ConnectionString
SourceId = oArgs(0)
ManagedEntityId = oArgs(1)
TargetComputerID = oArgs(2)
InstanceName = oArgs(3)
DataSource= oArgs(4)

Dim oAPI, oSQLDiscoveryData, connString
Set oAPI = CreateObject("MOM.ScriptAPI")
Set oSQLDiscoveryData = oAPI.CreateDiscoveryData(0, SourceId, ManagedEntityId)
ConnectionString= "Provider=SQLOLEDB;Data Source=" + DataSource+ "; Initial Catalog=master;Integrated Security=SSPI"

' Calling these functions in this order is very important
' to capture the right time stamps for discovery
DoSysDatabaseDiscovery
DoDatabaseDiscovery
Call oAPI.Return(oSQLDiscoveryData)
WScript.Quit()

'---------------------------------------------------------------------------
'Add a property to the discovery data if not null
'---------------------------------------------------------------------------
Sub AddPropertyIfNotNull(ByRef discData, prop, value)
if NOT isNull(value) Then
Call discData.AddProperty(prop, value)
End if
End Sub

'---------------------------------------------------------------------------
'Perform discovery on sys.Databases table
'---------------------------------------------------------------------------
Sub DoSysDatabaseDiscovery

Dim cnADOConnection
Set cnADOConnection = CreateObject("ADODB.Connection")
cnADOConnection.Open ConnectionString

Dim oResults, query, oInst
dim EngineModelCollation

' Get the Engine Model Collation first
query = "SELECT collation_name FROM sys.databases WHERE [name] = N'model'"
Set oResults = cnADOConnection.Execute(query)
EngineModelCollation = oResults(0)

query = "SELECT " &amp; _
"name, " &amp; _
"database_id as [ID], " &amp; _
"is_honor_broker_priority_on, " &amp; _
"DateAdd(MINUTE, DateDiff(MINUTE, GETDATE(), GETUTCDATE()),create_date), " &amp; _
"compatibility_level, " &amp; _
"is_read_only, " &amp; _
"is_auto_close_on, " &amp; _
"is_auto_shrink_on, " &amp; _
"state_desc as [Status], " &amp; _
"is_in_standby, " &amp; _
"is_cleanly_shutdown, " &amp; _
"is_supplemental_logging_enabled, " &amp; _
"snapshot_isolation_state_desc, " &amp; _
"is_read_committed_snapshot_on, " &amp; _
"page_verify_option_desc as [PageVerify], " &amp; _
"is_auto_create_stats_on, " &amp; _
"is_auto_update_stats_on, " &amp; _
"is_auto_update_stats_async_on, " &amp; _
"is_ansi_null_default_on, " &amp; _
"is_ansi_nulls_on, " &amp; _
"is_ansi_padding_on, " &amp; _
"is_ansi_warnings_on, " &amp; _
"is_arithabort_on, " &amp; _
"is_concat_null_yields_null_on, " &amp; _
"is_numeric_roundabort_on, " &amp; _
"is_quoted_identifier_on, " &amp; _
"is_recursive_triggers_on, " &amp; _
"is_cursor_close_on_commit_on, " &amp; _
"is_local_cursor_default, " &amp; _
"is_fulltext_enabled, " &amp; _
"is_trustworthy_on, " &amp; _
"is_db_chaining_on, " &amp; _
"is_parameterization_forced, " &amp; _
"is_master_key_encrypted_by_server, " &amp; _
"is_published, " &amp; _
"is_subscribed, " &amp; _
"is_merge_published, " &amp; _
"is_distributor, " &amp; _
"is_sync_with_backup, " &amp; _
"is_broker_enabled, " &amp; _
"log_reuse_wait_desc, " &amp; _
"is_date_correlation_on, " &amp; _
"is_cdc_enabled, " &amp; _
"is_encrypted " &amp; _
"FROM sys.databases where source_database_id IS NULL"

Set oResults = cnADOConnection.Execute(query)



Do While Not oResults.EOF
dim sStatus
set sStatus = oResults(8)
Set oInst = oSQLDiscoveryData.CreateClassInstance("$MPElement[Name='KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database']$")

' Set properties
Call AddPropertyIfNotNull(oInst, "$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", TargetComputerID)
Call AddPropertyIfNotNull(oInst, "$MPElement[Name='SQL!Microsoft.SQLServer.ServerRole']/InstanceName$", InstanceName)
Call AddPropertyIfNotNull(oInst, "$MPElement[Name='SQL!Microsoft.SQLServer.Database']/DatabaseName$", oResults(0))
Call AddPropertyIfNotNull(oInst, "$MPElement[Name='KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database']/DatabaseId$", oResults(1))
Call AddPropertyIfNotNull(oInst, "$MPElement[Name='KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database']/HonorBrokerPriority$", oResults(2))
Call AddPropertyIfNotNull(oInst, "$MPElement[Name='KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database']/CreateDate$", oResults(3))
Call AddPropertyIfNotNull(oInst, "$MPElement[Name='KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database']/CompatibilityLevel$", oResults(4))
Call AddPropertyIfNotNull(oInst, "$MPElement[Name='KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database']/ReadOnly$", oResults(5))
Call AddPropertyIfNotNull(oInst, "$MPElement[Name='KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database']/AutoClose$", oResults(6))
Call AddPropertyIfNotNull(oInst, "$MPElement[Name='KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database']/AutoShrink$", oResults(7))
Call AddPropertyIfNotNull(oInst, "$MPElement[Name='KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database']/Status$", sStatus)
Call AddPropertyIfNotNull(oInst, "$MPElement[Name='KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database']/StandBy$", oResults(9))
Call AddPropertyIfNotNull(oInst, "$MPElement[Name='KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database']/CleanlyShutdown$", oResults(10))
Call AddPropertyIfNotNull(oInst, "$MPElement[Name='KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database']/SupplementalLoggingEnabled$", oResults(11))
Call AddPropertyIfNotNull(oInst, "$MPElement[Name='KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database']/SnapshotIsolationState$", oResults(12))
Call AddPropertyIfNotNull(oInst, "$MPElement[Name='KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database']/IsReadCommittedSnapshotOn$", oResults(13))
Call AddPropertyIfNotNull(oInst, "$MPElement[Name='KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database']/PageVerify$", oResults(14))
Call AddPropertyIfNotNull(oInst, "$MPElement[Name='KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database']/AutoCreateStatisticsEnabled$", oResults(15))
Call AddPropertyIfNotNull(oInst, "$MPElement[Name='KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database']/AutoUpdateStatisticsEnabled$", oResults(16))
Call AddPropertyIfNotNull(oInst, "$MPElement[Name='KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database']/AutoUpdateStatisticsAsync$", oResults(17))
Call AddPropertyIfNotNull(oInst, "$MPElement[Name='KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database']/AnsiNullDefault$", oResults(18))
Call AddPropertyIfNotNull(oInst, "$MPElement[Name='KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database']/AnsiNullsEnabled$", oResults(19))
Call AddPropertyIfNotNull(oInst, "$MPElement[Name='KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database']/AnsiPaddingEnabled$", oResults(20))
Call AddPropertyIfNotNull(oInst, "$MPElement[Name='KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database']/AnsiWarningsEnabled$", oResults(21))
Call AddPropertyIfNotNull(oInst, "$MPElement[Name='KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database']/ArithmeticAbortEnabled$", oResults(22))
Call AddPropertyIfNotNull(oInst, "$MPElement[Name='KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database']/ConcatenateNullYieldsNull$", oResults(23))
Call AddPropertyIfNotNull(oInst, "$MPElement[Name='KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database']/NumericRoundAbortEnabled$", oResults(24))
Call AddPropertyIfNotNull(oInst, "$MPElement[Name='KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database']/QuotedIdentifiersEnabled$", oResults(25))
Call AddPropertyIfNotNull(oInst, "$MPElement[Name='KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database']/RecursiveTriggersEnabled$", oResults(26))
Call AddPropertyIfNotNull(oInst, "$MPElement[Name='KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database']/CloseCursorsOnCommitEnabled$", oResults(27))
Call AddPropertyIfNotNull(oInst, "$MPElement[Name='KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database']/LocalCursorsDefault$", oResults(28))
Call AddPropertyIfNotNull(oInst, "$MPElement[Name='KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database']/IsFullTextEnabled$", oResults(29))
Call AddPropertyIfNotNull(oInst, "$MPElement[Name='KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database']/Trustworthy$", oResults(30))
Call AddPropertyIfNotNull(oInst, "$MPElement[Name='KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database']/DatabaseOwnershipChaining$", oResults(31))
Call AddPropertyIfNotNull(oInst, "$MPElement[Name='KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database']/IsParameterizationForced$", oResults(32))
Call AddPropertyIfNotNull(oInst, "$MPElement[Name='KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database']/IsMasterKeyEncryptedByServer$", oResults(33))
Call AddPropertyIfNotNull(oInst, "$MPElement[Name='KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database']/IsPublished$", oResults(34))
Call AddPropertyIfNotNull(oInst, "$MPElement[Name='KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database']/IsSubscribed$", oResults(35))
Call AddPropertyIfNotNull(oInst, "$MPElement[Name='KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database']/IsMergePublished$", oResults(36))
Call AddPropertyIfNotNull(oInst, "$MPElement[Name='KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database']/IsDistributor$", oResults(37))
Call AddPropertyIfNotNull(oInst, "$MPElement[Name='KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database']/IsSyncWithBackup$", oResults(38))
Call AddPropertyIfNotNull(oInst, "$MPElement[Name='KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database']/BrokerEnabled$", oResults(39))
Call AddPropertyIfNotNull(oInst, "$MPElement[Name='KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database']/LogReuseWaitStatus$", oResults(40))
Call AddPropertyIfNotNull(oInst, "$MPElement[Name='KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database']/DateCorrelationOptimization$", oResults(41))
Call AddPropertyIfNotNull(oInst, "$MPElement[Name='KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database']/IsCDCEnabled$", oResults(42))
Call AddPropertyIfNotNull(oInst, "$MPElement[Name='KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database']/EncryptionEnabled$", oResults(43))
Call AddPropertyIfNotNull(oInst, "$MPElement[Name='KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database']/EngineModelCollation$", EngineModelCollation)

if oResults(0) = "model" or oResults(0) = "master" or oResults(0) = "tempdb" or oResults(0) = "msdb" then
Call AddPropertyIfNotNull(oInst, "$MPElement[Name='KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database']/IsSharepointSSRSSystemDatabase$", true)
else
Call AddPropertyIfNotNull(oInst, "$MPElement[Name='KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database']/IsSharepointSSRSSystemDatabase$", false)
end if

Call AddPerDatabaseProperties(sStatus, oInst, oResults(0))

Call oSQLDiscoveryData.AddInstance(oInst)

oResults.MoveNext
Loop

Set oResults = Nothing
cnADOConnection.Close

End Sub

'---------------------------------------------------------------------------
'perform discovery for mirroring and Updatability
'---------------------------------------------------------------------------
Sub DoDatabaseDiscovery

Dim cnADOConnection
Set cnADOConnection = CreateObject("ADODB.Connection")
cnADOConnection.Open ConnectionString

Dim oResults, query, oInst
query = "SELECT a.name, " &amp; _
"CAST(case when b.mirroring_partner_name is null then 0 else 1 end AS bit) AS [IsMirroringEnabled], b.mirroring_role_desc " &amp; _
"FROM sys.databases a, sys.database_mirroring b " &amp; _
"WHERE a.database_id = b.database_id and a.source_database_id IS NULL"

Set oResults = cnADOConnection.Execute(query)

Dim scriptEndTime
scriptEndTime = GetUTCNow()

Do While Not oResults.EOF
Set oInst = oSQLDiscoveryData.CreateClassInstance("$MPElement[Name='KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database']$")

' Set properties
Call AddPropertyIfNotNull(oInst, "$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", TargetComputerID)
Call AddPropertyIfNotNull(oInst, "$MPElement[Name='SQL!Microsoft.SQLServer.ServerRole']/InstanceName$", InstanceName)
Call AddPropertyIfNotNull(oInst, "$MPElement[Name='SQL!Microsoft.SQLServer.Database']/DatabaseName$", oResults(0))
Call AddPropertyIfNotNull(oInst, "$MPElement[Name='KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database']/IsMirroringEnabled$", oResults(1))
Call AddPropertyIfNotNull(oInst, "$MPElement[Name='KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database']/MirroringRole$", oResults(2))

Call oSQLDiscoveryData.AddInstance(oInst)
oResults.MoveNext
Loop

Set oResults = Nothing
cnADOConnection.Close
End Sub

Function EscapeConnectionString(ByVal param)
param = Replace(param, "'", "''")
EscapeConnectionString = param
End Function

' Some properties requires us to connect to the database in order to
' get the data. This function does just that.

Sub AddPerDatabaseProperties(sStatus, oInst, dbName)
If sStatus = "ONLINE" then
Dim cnADOConnection, perDatabaseConnectionString
Set cnADOConnection = CreateObject("ADODB.Connection")
perDatabaseConnectionString = "Provider=SQLOLEDB;Data Source=" + DataSource+ "; Initial Catalog='" + EscapeConnectionString(dbName) + "';Integrated Security=SSPI"

' On Error Resume Next

cnADOConnection.Open perDatabaseConnectionString

Dim oResults, query, bValue, intValue
bValue = false
intValue = 0

' The following code was added by ericzha for new database config points SystemCatalogUpdated,TargetRecoveryTimeInSeconds, Containment, FiletableNonTransactedAccess

' Check if this is a SQL 2012 database

Dim version
query = "select SERVERPROPERTY('ProductVersion')"
Set oResults = cnADOConnection.Execute(query)
version = CStr(oResults(0))
version = CInt(Mid(version,1, InStr(1,version,".",1)-1))
Set oResults = Nothing

' Config points for all SQL versions

' #1 SystemCatalogUpdated
query = "exec sp_executesql N'SET NOCOUNT ON; DECLARE @dbinfo TABLE(ParentObject nvarchar(255),Object nvarchar(255),Field nvarchar(255),Value nvarchar(255)); INSERT INTO @dbinfo EXEC (''DBCC DBINFO ([" + EscapeConnectionString(EscapeConnectionString(dbName)) + "]) WITH TABLERESULTS ''); SELECT CASE [Value] WHEN N''1900-01-01 00:00:00.000'' THEN 0 ELSE 1 END AS SystemCatalog_UpdatedManually_DB_Unsupported FROM @dbinfo WHERE ParentObject = N''DBINFO STRUCTURE:'' AND Field = N''dbi_updSysCatalog''; SET NOCOUNT OFF;'"

Set oResults = cnADOConnection.Execute(query)
bValue = false
bValue = CBool(oResults(0))
Call AddPropertyIfNotNull(oInst, "$MPElement[Name='KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database']/SystemCatalogUpdated$", bValue)
Set oResults = Nothing

' Config points that are introduced since SQL 2012

If version &gt;= 11 Then

' #2 TargetRecoveryTimeInSeconds; #3 Containment

intValue=0
query = "select target_recovery_time_in_seconds, containment from sys.databases where name = '" &amp; EscapeConnectionString(dbName) &amp; "'"
Set oResults = cnADOConnection.Execute(query)
intValue = CInt(oResults(0))
Call AddPropertyIfNotNull(oInst, "$MPElement[Name='KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database']/TargetRecoveryTimeInSeconds$", intValue)
intValue = CInt(oResults(1))
Call AddPropertyIfNotNull(oInst, "$MPElement[Name='KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database']/Containment$", intValue)
Set oResults = Nothing

' #4 FiletableNonTransactedAccess

intValue=0
query = "select non_transacted_access from sys.database_filestream_options where database_id = db_id('" &amp; EscapeConnectionString(dbName) &amp; "')"
Set oResults = cnADOConnection.Execute(query)
intValue = CInt(oResults(0))
Call AddPropertyIfNotNull(oInst, "$MPElement[Name='KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database']/FiletableNonTransactedAccess$", intValue)
Set oResults = Nothing

End If

' End of modification by ericzha

' Begin: Edited by v-jobzha
' #5 DataBaseGuid
Dim strDataBaseGuid
query = "select database_guid from sys.database_recovery_status where database_id = db_id('" &amp; EscapeConnectionString(dbName) &amp; "')"
Set oResults = cnADOConnection.Execute(query)
strDataBaseGuid = oResults(0)
Call AddPropertyIfNotNull(oInst, "$MPElement[Name='KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database']/DataBaseGuid$", strDataBaseGuid)
Set oResults = Nothing

' #6 FamilyGuid
Dim strFamilyGuid
query = "select family_guid from sys.database_recovery_status where database_id = db_id('" &amp; EscapeConnectionString(dbName) &amp; "')"
Set oResults = cnADOConnection.Execute(query)
strFamilyGuid = oResults(0)
Call AddPropertyIfNotNull(oInst, "$MPElement[Name='KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database']/FamilyGuid$", strFamilyGuid)
Set oResults = Nothing
' End: Edited by v-jobzha

' Check if this is a Sharepoint database
query = "select case SUM(query1.IndividualCounts) " &amp; _
"when 14 then 1 else 0 end as [SharePointDatabase] from " &amp; _
"(select COUNT(*) as 'IndividualCounts' from sys.objects where " &amp; _
"([name] = N'Versions' and [type] = 'U') or ([name] = N'Versions_PK' and [type] = 'PK') " &amp; _
"union all select COUNT(*) " &amp; _
"from sys.columns where [object_id] = OBJECT_ID(N'Versions',N'U') " &amp; _
"union all select COUNT(*) from sys.index_columns " &amp; _
"where [object_id] = OBJECT_ID(N'Versions',N'U') and [index_id] = 1) AS query1"

Set oResults = cnADOConnection.Execute(query)
bValue = CBool(oResults(0))
Call AddPropertyIfNotNull(oInst, "$MPElement[Name='KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database']/IsSharepointDatabase$", bValue)
Set oResults = Nothing

' Check if this is a SSRS database

query = "select case SUM(query1.IndividualCounts) " &amp; _
"when 5 then 1 else 0 end as [SharePointDatabase] from " &amp; _
"(select COUNT(*) as 'IndividualCounts' from sys.objects where " &amp; _
"([name] = N'Segment' and [type] = 'U') or ([name] = N'PK_Segment' and [type] = 'PK') " &amp; _
"union all select COUNT(*) " &amp; _
"from sys.columns where [object_id] = OBJECT_ID(N'Segment',N'U') " &amp; _
"union all select COUNT(*) from sys.index_columns " &amp; _
"where [object_id] = OBJECT_ID(N'Segment',N'U') and [index_id] = 1) AS query1"

bValue = false
Set oResults = cnADOConnection.Execute(query)
bValue = CBool(oResults(0))
Call AddPropertyIfNotNull(oInst, "$MPElement[Name='KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database']/IsSSRSDatabase$", bValue)
Set oResults = Nothing
cnADOConnection.Close
' On Error Goto 0
Else
' Set the properties to false.
Call AddPropertyIfNotNull(oInst, "$MPElement[Name='KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database']/IsSharepointDatabase$", false)
Call AddPropertyIfNotNull(oInst, "$MPElement[Name='KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database']/IsSSRSDatabase$", false)
End If
End Sub

'---------------------------------------------------------------------------
'This function returns the UTC time by looking at the time skew in registry
'and correcting for it.
'---------------------------------------------------------------------------
Function GetUTCNow()
Dim localTime, wScriptShell, registryKey, offsetMinutes, utcTime
localTime = now
set wScriptShell = CreateObject("WScript.Shell")
registryKey = "HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\TimeZoneInformation\ActiveTimeBias"
offsetMinutes = wScriptShell.RegRead(registryKey)
utcTime = dateadd("n", offsetMinutes, localTime)
GetUTCNow = utcTime
End Function
</Script></ScriptBody>
<TimeoutSeconds>300</TimeoutSeconds>
<IntervalInSeconds>15399</IntervalInSeconds>
</DataSource>
</Discovery>