Obtaining Class Instances
If you establish a direct connection with a cluster node (see Making Direct Connections), you can obtain instances of Network Load Balancing (NLB) provider classes as follows:
- Use the SWbemServices.InstancesOf method to get a collection of MicrosoftNLB_Node objects. The collection will always return the node you are connected to first, or you can use the object's Name property to identify a particular node. Note that the nodes you will be able to enumerate depend on several factors. For more information see Enumerating Objects.
- Use the SWbemServices.InstancesOf method to get a collection of MicrosoftNLB_NodeSetting objects. The collection will always return the MicrosoftNLB_NodeSetting corresponding to the node you are connected to first, or you can use the MicrosoftNLB_NodeSetting object's Name property to identify a particular node setting. Note that the node settings you will be able to enumerate depend on several factors. For more information see Enumerating Objects.
- Use the MicrosoftNLB_NodeSetting.GetPortRule method to get instances of MicrosoftNLB_PortRule objects.
The following code snippet demonstrates how to obtain instances of NLB provider classes. For a more detailed code example, see NLBScriptLib.vbs.
'Set configuration data.
strClusterIP = "172.50.66.14"
strHostID = "1"
strDIP = "172.50.35.12"
strKey = strClusterIP & ":" & strHostID
strNamespace = "root\MicrosoftNLB"
strUser = "Administrator"
strPassword = ""
strPortNumber = "65535"
'Make a direct connection.
Set oLoc = CreateObject("WbemScripting.SWbemLocator")
Set oSvc = oLoc.ConnectServer(strDIP, _
strNamespace, _
strUser, _
strPassword)
oLoc.Security_.ImpersonationLevel = 3
'Get a node instance.
Set oNodes = oSvc.InstancesOf ("MicrosoftNLB_Node")
For Each oNode in oNodes
' The first one is the one we want
Exit For
Next
'Get a node setting instance.
Set oNodeSettings = oSvc.InstancesOf ("MicrosoftNLB_NodeSetting")
For Each oNodeSetting in oNodeSettings
' The first one is the one we want
Exit For
Next
'Get a port rule instance.
oNodeSetting.GetPortRule CLng(strPortNumber), oPortRule
WScript.Echo oPortRule.Name
Set oPortRule = Nothing
Set oNodeSetting = Nothing
Set oNodeSettings = Nothing
Set oNode = Nothing
Set oNodes = Nothing
Set oSvc = Nothing
Set oLoc = Nothing