Microsoft System Center Service Manager의 속성을 검색합니다.
Knowledge Base article:
요약
이 검색은 Service Manager 속성을 채웁니다. 검색은 가져온 직후 실행된 다음 동기화 시간인 13:00에 다시 실행됩니다. 그 다음에는 24시간 간격으로 실행됩니다. 동기화 시간, 빈도 및 시간 제한은 변경할 수 있습니다. 인수는 변경하지 않는 것이 좋습니다.
'*************************************************************************
' $ScriptName: "GetSqlDriverName" $
'
' Purpose: This script is used to get SQL Driver name.
'
' $File: GetSqlDriverName.vbs $
'*************************************************************************
Option Explicit
Function GetSqlDriverName
Dim oAPI1, oReg
Const HKEY_LOCAL_MACHINE = &H80000002
Dim strComputer, strDriverPath, strKeyPath, intValue, strValueName,arrSubKeys,oSubkey,strNewKeyPath,intDotIndex
strComputer = "."
strDriverPath="SQLOLEDB"
Set oReg=GetObject("winmgmts:\\" & _
strComputer & "\root\default:StdRegProv")
strKeyPath = "SOFTWARE\ODBC\ODBCINST.INI"
oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
For Each oSubkey In arrSubKeys
intValue = InStr(oSubkey, "SQL Server Native Client")
if intValue <> 0 Then
strValueName = "Driver"
strNewKeyPath = strKeyPath&"\"&oSubkey
oReg.GetStringValue HKEY_LOCAL_MACHINE, strNewKeyPath, strValueName , strDriverPath
strDriverPath = Mid (strDriverPath, InStrRev(strDriverPath, "\")+1)
intDotIndex = InStr(strDriverPath, ".")
strDriverPath = Left(strDriverPath , intDotIndex-1)
end if
Next
GetSqlDriverName = strDriverPath
End Function
'*************************************************************************
' ScriptName: ManagementServerPropertyDiscovery.vbs
'
' Purpose - Populate properties of SM Management Server
'
' Parameters - 0 - discovery id
' 1 - Target managed entity id
' 2 - Host Computer Principal Name
' 3 - Version
'*************************************************************************
SetLocale("en-us")
On Error Resume Next
Dim oAPI, sourceId, managedEntityId, hostCompPrincipalName, discoveryData, serverRunningWorkflows, isRunningWorkflows, version
'Creating discovery data
Call oAPI.LogScriptEvent("ManagementServerPropertyDiscovery.vbs", 3000, 4, "Starting discovery of Service Manager Management Server Properties.")
Set discoveryData = oAPI.CreateDiscoveryData(0, sourceId, managedEntityId)
'Get management group name from registry
Dim oReg, iResult, arrSubKeys, managementGroupName, oMgtServer, smDbHostName, smDbName
Set oReg = GetObject("winmgmts:\\" & hostCompPrincipalName & "\root\default:StdRegProv")
If Err <> 0 Then
Call oAPI.LogScriptEvent("ManagementServerPropertyDiscovery.vbs", 3000, 4, "Unable to bind to WMI registry provider on " & hostCompPrincipalName & ". Terminating Discovery.")
Call oAPI.Return(discoveryData)
WScript.Quit
End if
Const HKLM = &H80000002
If version = "2010" or version = "2012" then
iResult = oReg.Enumkey(HKLM, "SOFTWARE\Microsoft\Microsoft Operations Manager\3.0\Server Management Groups", arrSubKeys)
If iResult = 0 then
managementGroupName = arrSubKeys(0)
iResult = oReg.GetStringValue(HKLM, "SOFTWARE\Microsoft\System Center\2010\Common\Database", "DatabaseServerName", smDbHostName)
If iResult = 0 then
iResult = oReg.GetStringValue(HKLM, "SOFTWARE\Microsoft\System Center\2010\Common\Database", "DatabaseName", smDbName)
If iResult = 0 then
'Instantiate Management Server Class
Call oAPI.LogScriptEvent("ManagementServerPropertyDiscovery.vbs", 3000, 4, "Discovered SCSM " & version & " Management Server Properties.")
If version = "2010" then
Set oMgtServer = discoveryData.CreateClassInstance("$MPElement[Name='SM!Microsoft.SystemCenter.ServiceManager.SmManagementServer.2010']$")
ElseIf version = "2012" then
Set oMgtServer = discoveryData.CreateClassInstance("$MPElement[Name='SM!Microsoft.SystemCenter.ServiceManager.SmManagementServer.2012']$")
End If
Call oMgtServer.AddProperty("$MPElement[Name='SM!Microsoft.SystemCenter.ServiceManager.ManagementServer']/ManagementGroupName$", managementGroupName)
Call oMgtServer.AddProperty("$MPElement[Name='SM!Microsoft.SystemCenter.ServiceManager.SmManagementServer']/SmDbHostName$", smDbHostName)
Call oMgtServer.AddProperty("$MPElement[Name='SM!Microsoft.SystemCenter.ServiceManager.SmManagementServer']/SMDbName$", smDbName)
Call oMgtServer.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$",hostCompPrincipalName)
Dim connectionString, cnADOConnection, oResults,oQuery,sourceName, strDriverName
strDriverName = GetSqlDriverName
connectionString = "Provider=" & strDriverName & "; Data Source=" & smDbHostName & "; Trusted_Connection=Yes; Initial Catalog=" & smDbName & ";"
Set cnADOConnection = CreateObject("ADODB.Connection")
cnADOConnection.Open connectionString
cnADOConnection.CommandTimeout = 300
oQuery = "select CONVERT(nvarchar(4000),B.Name) as ServerName from ScopedInstanceTargetClass SCT inner join ManagedType MT on MT.ManagedTypeId = SCT.ManagedTypeId inner join BaseManagedEntity B on B.BaseManagedEntityId = SCT.ScopedInstanceId where MT.TypeName ='Microsoft.SystemCenter.WorkflowTarget'"
Set oResults = CreateObject("ADODB.Recordset")
oResults.Open oQuery, cnADOConnection, 3, 3
If oResults.State <> 0 and oResults.RecordCount > 0 Then
Do Until oResults.EOF
serverRunningWorkflows = oResults.Fields("ServerName")
oResults.MoveNext
Loop
End If
If oResults.State <> 0 Then
oResults.Close
End If
cnADOConnection.Close
if(isEmpty(serverRunningWorkflows)) Then
serverRunningWorkflows = ""
End If
If LCase(hostCompPrincipalName) = LCase(serverRunningWorkflows) then
isRunningWorkflows = true
Else
isRunningWorkflows = false
End If
Call oMgtServer.AddProperty("$MPElement[Name='SM!Microsoft.SystemCenter.ServiceManager.SmManagementServer']/isRunningWorkflows$",isRunningWorkflows)
Call discoveryData.AddInstance(oMgtServer)
End If
End If
End If
End If
Call oAPI.Return(discoveryData)
Call oAPI.LogScriptEvent("ManagementServerPropertyDiscovery.vbs", 3000, 4, "Finishined Discovering SCSM " & version &" Management Server Properties.")
WScript.Quit