Windows OS Language Discovery (Windows 2003)

Custom.Microsoft.Windows.ScheduledTask.Server.2003.OperatingSystem.DiscoverByScript (Discovery)

Discovers the language of the OS. Used to interpret the output of the scheduled task command 'schtask.exe'.

Element properties:

TargetMicrosoft.Windows.Server.2003.OperatingSystem
EnabledFalse
Frequency87003
RemotableFalse

Object Discovery Details:

Discovered Classes and their attribuets:
Discovered relationships and their attribuets:

Member Modules:

ID Module Type TypeId RunAs 
DScriptL DataSource Microsoft.Windows.TimedScript.DiscoveryProvider Default

Source Code:

<Discovery ID="Custom.Microsoft.Windows.ScheduledTask.Server.2003.OperatingSystem.DiscoverByScript" Enabled="false" Target="Windows2003!Microsoft.Windows.Server.2003.OperatingSystem" ConfirmDelivery="false" Remotable="false" Priority="Normal">
<Category>Discovery</Category>
<DiscoveryTypes>
<DiscoveryClass TypeID="Custom.Microsoft.Windows.ScheduledTask.Server.2003.OperatingSystem">
<Property TypeID="Custom.Microsoft.Windows.ScheduledTask.Server.2003.OperatingSystem" PropertyID="OSLanguageInt"/>
<Property TypeID="Custom.Microsoft.Windows.ScheduledTask.Server.2003.OperatingSystem" PropertyID="OSLanguage"/>
</DiscoveryClass>
<DiscoveryRelationship TypeID="Windows!Microsoft.Windows.ComputerHostsOperatingSystem"/>
</DiscoveryTypes>
<DataSource ID="DScriptL" TypeID="Windows!Microsoft.Windows.TimedScript.DiscoveryProvider">
<IntervalSeconds>87003</IntervalSeconds>
<SyncTime/>
<ScriptName>Custom.Microsoft.Windows.ScheduledTask.OSLanguage.vbs</ScriptName>
<Arguments>$MPElement$ $Target/Id$ $Target/Host/Property[Type="Windows!Microsoft.Windows.Computer"]/PrincipalName$</Arguments>
<ScriptBody><Script>'*************************************************************************
' Script Name - Custom.Microsoft.Windows.ScheduledTask.OSLanguage.vbs
'
' Purpose - Queries WMI to discover the OS language and translates the
' OSLanguage integer to a string
' That string is later used by the Scheduled Task discovery
' script to 'translate' localized output of schtask.exe
'
' Parameters 1 SourceID
' 2 ManagedEntity
' 3 TargetComputer
'
' Restrictions Currently only English, French and German are supported
'
' 11. April 2009 - Raphael Burri / [email protected]
'*************************************************************************


Option Explicit

'It is important to switch to en-us locale since otherwise functions like CDbl will work incorrectly with some data returned by other data providers
SetLocale("en-us")

'OS Language Constants
Const ENGLISH_UN = 9
Const ENGLISH_US = 1033
Const ENGLISH_UK = 2057
Const ENGLISH_AU = 3081
Const ENGLISH_CA = 4105
Const ENGLISH_NZ = 5129
Const ENGLISH_IE = 6153
Const ENGLISH_SA = 7177
Const ENGLISH_JC = 8201
Const ENGLISH_BZ = 10249
Const ENGLISH_TT = 11237

Const DUTCH_NL = 1043
Const DUTCH_BE = 2067

Const ITALIAN_I = 1040
Const ITALIAN_CH = 2064

Const GERMAN_GE = 1031
Const GERMAN_CH = 2055
Const GERMAN_AT = 3079
Const GERMAN_LU = 4103
Const GERMAN_LI = 5127

Const FRENCH_FR = 1036
Const FRENCH_BE = 2060
Const FRENCH_CA = 3084
Const FRENCH_CH = 4108
Const FRENCH_LU = 5132

Const PORTUGUESE_BR = 1046
Const PORTUGUESE_PT = 2070

Const SPANISH_TRAD = 1034
Const SPANISH_MX = 2058
Const SPANISH_INT = 3082
Const SPANISH_GT = 4106
Const SPANISH_CR = 5130
Const SPANISH_PN = 6154
Const SPANISH_DR = 7178
Const SPANISH_VZ = 8202
Const SPANISH_CO = 9226
Const SPANISH_PE = 10250
Const SPANISH_AG = 11274
Const SPANISH_EQ = 12298
Const SPANISH_CH = 13322
Const SPANISH_UR = 14346
Const SPANISH_PA = 15370
Const SPANISH_BO = 16394
Const SPANISH_ES = 17418
Const SPANISH_HO = 18442
Const SPANISH_NI = 19466
Const SPANISH_PR = 20490

Dim objArgs, objAPI, objDiscoveryData, objInst
Dim SourceID, ManagedEntityId, TargetComputer, strOSLang
Dim iOsLang

'get the parameters from the management pack
Set objArgs = WScript.Arguments
If objArgs.Count &lt; 3 Then
WScript.Quit -1
End If
SourceID = objArgs(0)
ManagedEntityId = objArgs(1)
TargetComputer = objArgs(2)

Set objAPI = CreateObject("MOM.ScriptAPI")

'get the OS language
iOsLang = GetOSLanguage
If iOsLang = ENGLISH_UN Or iOsLang = ENGLISH_US Or iOsLang = ENGLISH_UK Or iOsLang = ENGLISH_AU Or iOsLang = ENGLISH_CA Or iOsLang = ENGLISH_NZ Or iOsLang = ENGLISH_IE Or iOsLang = ENGLISH_SA Or iOsLang = ENGLISH_JC Or iOsLang = ENGLISH_BZ Or iOsLang = ENGLISH_TT Then
strOSLang = "ENGLISH"
ElseIf iOsLang = DUTCH_NL Or iOsLang = DUTCH_BE Then
strOSLang = "DUTCH"
ElseIf iOsLang = GERMAN_GE Or iOsLang = GERMAN_CH Or iOsLang = GERMAN_AT Or iOsLang = GERMAN_LU Or iOsLang = GERMAN_LI Then
strOSLang = "GERMAN"
ElseIf iOsLang = FRENCH_FR Or iOsLang = FRENCH_BE Or iOsLang = FRENCH_CA Or iOsLang = FRENCH_CH Or iOsLang = FRENCH_LU Then
strOSLang = "FRENCH"
ElseIf iOsLang = ITALIAN_I Or iOsLang = ITALIAN_CH Then
strOSLang = "ITALIAN"
ElseIf iOsLang = PORTUGUESE_BR Or iOsLang = PORTUGUESE_PT Then
strOSLang = "PORTUGUESE"
ElseIf iOsLang = SPANISH_TRAD Or iOsLang = SPANISH_MX Or iOsLang = SPANISH_INT Or iOsLang = SPANISH_GT Or iOsLang = SPANISH_CR Or iOsLang = SPANISH_PN Or iOsLang = SPANISH_DR Or iOsLang = SPANISH_VZ Or iOsLang = SPANISH_CO Or iOsLang = SPANISH_PE Or iOsLang = SPANISH_AG Or iOsLang = SPANISH_EQ Or iOsLang = SPANISH_CH Or iOsLang = SPANISH_PA Or iOsLang = SPANISH_UR Or iOsLang = SPANISH_BO Or iOsLang = SPANISH_ES Or iOsLang = SPANISH_HO Or iOsLang = SPANISH_NI Or iOsLang = SPANISH_PR Then
strOSLang = "SPANISH"
'other languages are not supported as no translation values have been added yet
Else
Call objAPI.LogScriptEvent("Custom.Microsoft.Windows.ScheduledTask.OSLanguage.vbs", 8094, 4, "The service discovery script for Scheduled Tasks on Windows Server 2003 will not work propely on localized windows versions. The language code of your OS is " &amp; CStr(iOSLAng) &amp; ". Please contact the management pack author to update the management pack for your language.")
WScript.Quit(1)

End If
'WScript.Echo "OS Language Code: " &amp; iOsLang &amp; " / " &amp; strOSLang

'prepare the discovery data bag
Set objDiscoveryData = objAPI.CreateDiscoveryData(0, SourceId, ManagedEntityId)

If iOsLang &gt; 0 Then

'define class
Set objInst = objDiscoveryData.CreateClassInstance("$MPElement[Name='Custom.Microsoft.Windows.ScheduledTask.Server.2003.OperatingSystem']$")
'add host primary key
Call objInst.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", TargetComputer)
'add class instance properties
Call objInst.AddProperty("$MPElement[Name='Custom.Microsoft.Windows.ScheduledTask.Server.2003.OperatingSystem']/OSLanguageInt$", iOsLang)
Call objInst.AddProperty("$MPElement[Name='Custom.Microsoft.Windows.ScheduledTask.Server.2003.OperatingSystem']/OSLanguage$", strOsLang)
'add this instance to the bag
Call objDiscoveryData.AddInstance(objInst)

End If

'return the discovery data to SCOM
Call objAPI.Return(objDiscoveryData)


Set objDiscoveryData = Nothing
Set objAPI = Nothing

WScript.Quit(0)

Function GetOSLanguage

Dim objWMI, objOS
Dim colOS

On Error Resume Next

Set objWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colOS = objWMI.ExecQuery ("Select * from Win32_OperatingSystem")

For Each objOS In colOS
GetOSLanguage = objOS.OSLanguage
Next

On Error Goto 0

End Function
</Script></ScriptBody>
<TimeoutSeconds>120</TimeoutSeconds>
<EventPolicy>
<StdOutMatches/>
<StdErrMatches>\a+</StdErrMatches>
<!--
<ExitCodeMatches>[^0]+</ExitCodeMatches>
-->
<ExitCodeMatches>[^(0|128)]+</ExitCodeMatches>
</EventPolicy>
</DataSource>
</Discovery>