Creates a new relationship instance object.



Parameter Type Description



The relationship type.

Return Value

Type Description


Returns a new instance of the MOMRelationshipInstance object.


When discovering class instances that you want to monitor, you must also discover the relationships between the instances. A relationship between objects means that one object depends on another object for its existence. A relationship can be one of several different types.

A relationship object must have two properties set with references to the source and target objects.

After an object is created, properties can be set. After the properties are set, the instance must be added to the discovery data by using the MOMDiscoveryData.AddInstance method, and the MOMScriptAPI.Return method must be called to submit the discovery data to MOM.


Platforms: Requires Windows Server 2003, Windows Vista, or Windows Server 2008

Version: Requires Operations Manager 2007


This example creates a relationship instance.

  Copy Code
Option Explicit
Dim oArgs
Set oArgs = WScript.Arguments

Dim oAPI
Set oAPI = CreateObject("MOM.ScriptAPI")

Dim SourceType, SourceId, ManagedEntityId, TargetComputer
SourceType = 0
' SourceId is the GUID of the discovery object that runs the script.
SourceId = oArgs(0)
' ManagedEntityId is the GUID of the computer class that is targeted by the script.
ManagedEntityId = oArgs(1)
' TargetComputer is the Fully Qualified Domain Name
' of the computer that is targeted by the script. The FQDN
' is within Arg(2) of the command prompt.
TargetComputer = oArgs(2)

Dim oDiscoveryData, oInst1, oInst2, oRelationship, oRelationshipComment1, oRelationshipComment2
Set oDiscoveryData = oAPI.CreateDiscoveryData(SourceType, SourceId, ManagedEntityId)
' Create two application instances.
Set oInst1 = oDiscoveryData.CreateClassInstance("$MPElement[Name='Microsoft.Demo.Scripting.Appy1']$")
Call oInst1.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName1$", TargetComputer)
Call oInst1.AddProperty("$MPElement[Name='Microsoft.Demo.Scripting.AppY1']/Name$", "ApplicationName1")
Call oDiscoveryData.AddInstance(oInst1)

Set oInst2 = oDiscoveryData.CreateClassInstance("$MPElement[Name='Microsoft.Demo.Scripting.Appy2']$")
Call oInst2.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName2$", TargetComputer)
Call oInst2.AddProperty("$MPElement[Name='Microsoft.Demo.Scripting.AppY2']/Name$", "ApplicationName2")
Call oDiscoveryData.AddInstance(oInst2)

' Create a relationship between the two instances.
Set oRelationship = oDiscoveryData.CreateRelationshipInstance("$MPElement[Name='Microsoft.Example.RelAContainsB']$")
oRelationship.Source = oInst1
oRelationship.Target = oInst2
' Add a property to the relationship.
oRelationshipComment1 = "Source comment"
oRelationshipComment2 = "Target comment"
Call oRelationship.AddProperty(oRelationshipComment1, oRelationshipComment2)
Call oDiscoveryData.AddInstance(oRelationship)

' Submit the application data to the Operations Manager database.
Call oAPI.Return(oDiscoveryData)

See Also

Send comments about this topic to Microsoft.