Set oAPI = CreateObject("MOM.ScriptAPI")
set oDiscoveryData = oAPI.CreateDiscoveryData(0, SourceId, ManagedEntityId)
''''''''Create the source of the relationship first:
set oTFSAT = oDiscoveryData.CreateClassInstance("$MPElement[Name='TeamFoundationServer2008.TFSApplicationTier']$")
call oTFSAT.AddProperty("$MPElement[Name='TeamFoundationServer2008.TFSApplicationTier']/TFSATComputerName$",vPrincipalName )
call oTFSAT.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", vPrincipalName )
''''''''Now Create the target of the relationship
'call TraceLogMessage("Creating the Target: TFSBuildService Class")
set oInstBld = oDiscoveryData.CreateClassInstance("$MPElement[Name='TeamFoundationServer2008.TFSBuildWebService']$")
call oInstBld.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", vPrincipalName )
call oInstBld.AddProperty("$MPElement[Name='MicrosoftWindowsInternetInformationServices2003!Microsoft.Windows.InternetInformationServices.2003.AspNetWebServiceEndpoint']/IISApplicationName$",vIISApplicationName )
call oInstBld.AddProperty("$MPElement[Name='MicrosoftWindowsInternetInformationServicesCommonLibrary!Microsoft.Windows.InternetInformationServices.WebSite']/SiteID$", vSiteID)
call oInstBld.AddProperty("$MPElement[Name='MicrosoftWindowsInternetInformationServices2003!Microsoft.Windows.InternetInformationServices.2003.AspNetWebServiceEndpoint']/ApplicationVRoot$", vApplicationVRoot)
call oInstBld.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", vApplicationVRoot)
'call TraceLogMessage("AddingInstanceData: for TfsBuildWebService")
call oDiscoveryData.AddInstance(oInstBld)
'call TraceLogMessage("Adding Relationship for TfsBuildWebService")
set oRelnShipATtoBld= oDiscoveryData.CreateRelationshipInstance("$MPElement[Name='TeamFoundationServer2008.TFSApplicationTierContainsTFSBuildWebService']$")
oRelnShipATtoBld.Source = oTFSAT
oRelnShipATtoBld.Target = oInstBld
'Call TraceLogMessage("Now Add the AT-To-BuildService Relationship Instance")
Call oDiscoveryData.AddInstance(oRelnShipATtoBld)
'###### Here an assumption is made that the ApplicationRoot is always of a format such as: /TEXT/TEXT/TEXT/TEXT/TEXT ie /LM/W3SVC/NNNNNNNNNNN/Root/Build.
'###### Rebuild the string for ApplicationVROOT to use /TEXT/TEXT/TEXT/TEXT/VersionControl
''''''''For some strange reason the ASP.NET MP does not detect VersionControl, Warehouse and Services end points. So they are added in the code below.
''''''''Now Create the 2nd target of the relationship, namely VersionControl
'call TraceLogMessage("Creating the Target: TFSVersionControlWebService Class")
set oInstVC = oDiscoveryData.CreateClassInstance("$MPElement[Name='TeamFoundationServer2008.TFSVersionControlWebService']$")
call oInstVC.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", vPrincipalName )
call oInstVC.AddProperty("$MPElement[Name='MicrosoftWindowsInternetInformationServices2003!Microsoft.Windows.InternetInformationServices.2003.AspNetWebServiceEndpoint']/IISApplicationName$","VersionControl" )
call oInstVC.AddProperty("$MPElement[Name='MicrosoftWindowsInternetInformationServicesCommonLibrary!Microsoft.Windows.InternetInformationServices.WebSite']/SiteID$", vSiteID)
call oInstVC.AddProperty("$MPElement[Name='MicrosoftWindowsInternetInformationServices2003!Microsoft.Windows.InternetInformationServices.2003.AspNetWebServiceEndpoint']/ApplicationVRoot$", newAppRoot)
call oInstVC.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", newAppRoot)
'call TraceLogMessage("AddingInstanceData: for TfsVersionControlWebService")
call oDiscoveryData.AddInstance(oInstVC)
'call TraceLogMessage("Adding Relationship for TfsVCWebService")
set oRelnShipATtoVC= oDiscoveryData.CreateRelationshipInstance("$MPElement[Name='TeamFoundationServer2008.TFSApplicationTierContainsTFSVCWebService']$")
oRelnShipATtoVC.Source = oTFSAT
oRelnShipATtoVC.Target = oInstVC
'Call TraceLogMessage("Now Add the AT-To-VC-Service Relationship Instance")
Call oDiscoveryData.AddInstance(oRelnShipATtoVC)
''''''''Now Create the 3nd target of the relationship, namely Warehouse
'call TraceLogMessage("Creating the Target: TFSWarehouseWebService Class")
newAppRoot = var1(0)&"/"&var1(1)&"/"&var1(2)&"/"&var1(3)&"/"&var1(4)&"/Warehouse"
set oInstWH = oDiscoveryData.CreateClassInstance("$MPElement[Name='TeamFoundationServer2008.TFSWaehouseWebService']$")
call oInstWH.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", vPrincipalName )
call oInstWH.AddProperty("$MPElement[Name='MicrosoftWindowsInternetInformationServices2003!Microsoft.Windows.InternetInformationServices.2003.AspNetWebServiceEndpoint']/IISApplicationName$","Warehouse" )
call oInstWH.AddProperty("$MPElement[Name='MicrosoftWindowsInternetInformationServicesCommonLibrary!Microsoft.Windows.InternetInformationServices.WebSite']/SiteID$", vSiteID)
call oInstWH.AddProperty("$MPElement[Name='MicrosoftWindowsInternetInformationServices2003!Microsoft.Windows.InternetInformationServices.2003.AspNetWebServiceEndpoint']/ApplicationVRoot$", newAppRoot)
call oInstWH.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", newAppRoot)
'call TraceLogMessage("AddingInstanceData: for TfsWarehouseWebService")
call oDiscoveryData.AddInstance(oInstWH)
'call TraceLogMessage("Adding Relationship for TfsVCWebService")
set oRelnShipATtoWH= oDiscoveryData.CreateRelationshipInstance("$MPElement[Name='TeamFoundationServer2008.TFSApplicationTierContainsWarehouseService']$")
oRelnShipATtoWH.Source = oTFSAT
oRelnShipATtoWH.Target = oInstWH
'Call TraceLogMessage("Now Add the AT-To-WH-Service Relationship Instance")
Call oDiscoveryData.AddInstance(oRelnShipATtoWH)
Call oAPI.Return(oDiscoveryData)
ELSE
'Call TraceLogMessage(" Not a Build Web Service : vIISApplicationName != Build ")
Wscript.Quit -1
END IF
'''##### TraceLogMessage ######################
Function TraceLogMessage(ByVal sMessage)
Dim lsEventInformation
WScript.Echo sMessage
' Retrieve the name of this (running) script
Dim FSO, ScriptFileName
Set FSO = CreateObject("Scripting.FileSystemObject")
ScriptFileName = FSO.GetFile(WScript.ScriptFullName).Name
Set FSO = Nothing
On Error Resume Next
Dim oAPITemp
Set oAPITemp = CreateObject("MOM.ScriptAPI")
lsEventInformation = 3
oAPITemp.LogScriptEvent ScriptFileName, 4000, lsEventInformation, sMessage
On Error Goto 0
End Function