-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathClass.And.Discovery.Script.VBScript.mpx
More file actions
129 lines (115 loc) · 5.88 KB
/
Class.And.Discovery.Script.VBScript.mpx
File metadata and controls
129 lines (115 loc) · 5.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<ManagementPackFragment SchemaVersion="2.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<!--
%%
Description:
A CLASS and DISCOVERY using a VBSCRIPT to create class instances
CompanyID - is a short abbreviation for your company with NO SPACES OR SPECIAL CHARACTERS ALLOWED
AppName - is a short name for your app with NO SPACES OR SPECIAL CHARACTERS ALLOWED
UniqueID - We need a Unique ID to reuse the fragment within the same MP. Use a shortened descriptive name with NO SPACES OR SPECIAL CHARACTERS ALLOWED
In this example we added a a couple additional class properties to demo that capability
Version: 1.4
LastModified: 12-Feb-2019
%%
In this fragment you need to replace:
##CompanyID##
##AppName##
##UniqueID##
This fragment depends on references:
RequiredReference: Alias="System", ID="System.Library"
RequiredReference: Alias="Windows", ID="Microsoft.Windows.Library"
@@Author=Kevin Holman@@
-->
<TypeDefinitions>
<EntityTypes>
<ClassTypes>
<ClassType ID="##CompanyID##.##AppName##.##UniqueID##.Class" Base="Windows!Microsoft.Windows.LocalApplication" Accessibility="Public" Abstract="false" Hosted="true" Singleton="false">
<Property ID="Version" Type="string"/>
<Property ID="Path" Type="string"/>
<!-- We choose Microsoft.Windows.LocalApplication as our generic base class -->
<!-- This specific fragment example has class properties for Version and Path as examples only. You can change or remove these if not desired -->
</ClassType>
</ClassTypes>
</EntityTypes>
</TypeDefinitions>
<Monitoring>
<Discoveries>
<Discovery ID="##CompanyID##.##AppName##.##UniqueID##.Class.Discovery" Target="Windows!Microsoft.Windows.Server.OperatingSystem" Enabled="true" ConfirmDelivery="false" Remotable="true" Priority="Normal">
<!-- We choose Microsoft.Windows.Server.OperatingSystem as the preferred target class to ensure this will run on all Windows Servers, but will not create duplicates on clusters -->
<Category>Discovery</Category>
<DiscoveryTypes>
<DiscoveryClass TypeID="##CompanyID##.##AppName##.##UniqueID##.Class">
<Property PropertyID="Version"/>
<Property PropertyID="Path"/>
</DiscoveryClass>
</DiscoveryTypes>
<DataSource ID="VBScriptDS" TypeID="Windows!Microsoft.Windows.TimedScript.DiscoveryProvider">
<IntervalSeconds>86400</IntervalSeconds>
<SyncTime/>
<ScriptName>##CompanyID##.##AppName##.##UniqueID##.Class.Discovery.vbs</ScriptName>
<Arguments>$MPElement$ $Target/Id$ $Target/Host/Property[Type="Windows!Microsoft.Windows.Computer"]/PrincipalName$</Arguments>
<ScriptBody><![CDATA[
Option Explicit
Dim oArgs
Set oArgs = WScript.Arguments
if oArgs.Count < 3 Then
Wscript.Quit -1
End If
SourceId = oArgs(0)
ManagedEntityId = oArgs(1)
TargetComputer = oArgs(2)
Dim StartTime,EndTime,sTime
'Capture script start time
StartTime = Now
dim oAPI, oDiscoveryData, oInst, SourceID, ManagedEntityId, TargetComputer
'Load MOMScript API and PropertyBag function
Set oAPI = CreateObject("MOM.ScriptAPI")
Set oDiscoveryData = oAPI.CreateDiscoveryData(0, SourceId, ManagedEntityId)
'Log script event that we are starting discovery
Call oAPI.LogScriptEvent("##CompanyID##.##AppName##.##UniqueID##.Class.Discovery.vbs", 1234, 0, "Starting script")
' Change your logic here to discover and create class instances based on an If statement
' In this example we are simply looking for the existence of a folder to create class instances
' We are hard coding properties but you could easily gather those in the script and set to variables
Dim oFso
Set oFso = CreateObject("Scripting.FileSystemObject")
If (oFso.FolderExists("C:\AuthorMPs")) Then
set oInst = oDiscoveryData.CreateClassInstance("$MPElement[Name='##CompanyID##.##AppName##.##UniqueID##.Class']$")
call oInst.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", TargetComputer)
call oInst.AddProperty("$MPElement[Name='##CompanyID##.##AppName##.##UniqueID##.Class']/Version$", "2.0")
call oInst.AddProperty("$MPElement[Name='##CompanyID##.##AppName##.##UniqueID##.Class']/Path$", "C:\AuthorMPs")
call oInst.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", TargetComputer)
call oDiscoveryData.AddInstance(oInst)
Else
'Log script event that we are ending discovery
Call oAPI.LogScriptEvent("##CompanyID##.##AppName##.##UniqueID##.Class.Discovery.vbs", 1234, 0, "No objects discovered")
End If
'Capture script runtime for logging
EndTime = Now
sTime = DateDiff("s", StartTime, EndTime)
'Log script event that we are ending discovery
Call oAPI.LogScriptEvent("##CompanyID##.##AppName##.##UniqueID##.Class.Discovery.vbs", 1234, 0, "Ending script. Script runtime in seconds: " & sTime)
Call oAPI.Return(oDiscoveryData)
]]></ScriptBody>
<TimeoutSeconds>120</TimeoutSeconds>
</DataSource>
</Discovery>
</Discoveries>
</Monitoring>
<LanguagePacks>
<LanguagePack ID="ENU" IsDefault="true">
<DisplayStrings>
<DisplayString ElementID="##CompanyID##.##AppName##.##UniqueID##.Class">
<Name>##CompanyID## ##AppName## ##UniqueID## Class</Name>
</DisplayString>
<DisplayString ElementID="##CompanyID##.##AppName##.##UniqueID##.Class" SubElementID="Version">
<Name>Version</Name>
</DisplayString>
<DisplayString ElementID="##CompanyID##.##AppName##.##UniqueID##.Class" SubElementID="Path">
<Name>Path</Name>
</DisplayString>
<DisplayString ElementID="##CompanyID##.##AppName##.##UniqueID##.Class.Discovery">
<Name>##CompanyID## ##AppName## ##UniqueID## Class Discovery</Name>
</DisplayString>
</DisplayStrings>
</LanguagePack>
</LanguagePacks>
</ManagementPackFragment>