Share via


How to Configure Network Discovery

Applies To: System Center Configuration Manager 2007, System Center Configuration Manager 2007 R2, System Center Configuration Manager 2007 R3, System Center Configuration Manager 2007 SP1, System Center Configuration Manager 2007 SP2

You configure the Network Discovery settings, in Microsoft System Center Configuration Manager 2007, by modifying the necessary site control file settings.

To configure Network Discovery

  1. Set up a connection to the SMS Provider.

  2. Make a connection to the Network Discovery section of the site control file by using the SMS_SCI_Component class.

  3. Loop through the array of available properties, making changes as needed.

  4. Commit the changes to the site control file.

  5. Make a connection to the Network Discovery section of the site control file by using the SMS_SCI_Configuration class.

  6. Loop through the array of available properties, making changes as needed.

  7. Commit the changes to the site control file.

Example

The following example sets the Network Discovery settings by using the SMS_SCI_Component and SMS_SCI_Configuration classes to connect to the site control file and change properties.

Note

Network Discovery is unusual, in that it requires setting both the SMS_SCI_Component and SMS_SCI_Configuration class properties to enable the component.

For information about calling the smple code, see Calling Configuration Manager Code Snippets.

Sub ConfigureNetworkDiscoverySettings(swbemServices,         _
                                      swbemContext,          _
                                      siteCode,              _
                                      enableDisableDiscovery)
 
    ' Load site control file and get the SMS_SCI_Component, SMS_NETWORK_DISCOVERY section.
    swbemServices.ExecMethod "SMS_SiteControlFile.Filetype=1,Sitecode=""" & siteCode & """", "Refresh", , , swbemContext

    ' Get the SMS_SCI_Component, SMS_NETWORK_DISCOVERY section of the site control file. 
    Query = "SELECT * FROM SMS_SCI_Component "       & _
    "WHERE ComponentName = 'SMS_NETWORK_DISCOVERY' " & _
    "AND SiteCode = '" & siteCode & "'"
              
    ' Get the SMS_NETWORK_DISCOVERY properties.
    Set SCIComponentSet = swbemServices.ExecQuery(Query, ,wbemFlagForwardOnly Or wbemFlagReturnImmediately, swbemContext)
                       
    ' Only one instance is returned from the query.
    For Each SCIComponent In SCIComponentSet

        ' Display the server name.
        wscript.echo "Server: " & SCIComponent.Name      
    
        ' Loop through the array of embedded SMS_EmbeddedProperty instances.
        For Each vProperty In SCIComponent.Props
            
            ' Setting: Discovery Enabled
            If vProperty.PropertyName = "Discovery Enabled" Then
                wscript.echo " "
                wscript.echo vProperty.PropertyName
                wscript.echo "Current value: " &  vProperty.Value1               
                
                ' Modify the value.
                vProperty.Value1 = enableDisableDiscovery
                wscript.echo "New value:     " & enableDisableDiscovery
            End If
                            
         Next
         
         ' Update the component in your copy of the site control file. Get the path
         ' to the updated object, which could be used later to retrieve the instance.
          Set SCICompPath = SCIComponent.Put_(wbemChangeFlagUpdateOnly, swbemContext)

    Next
    
    ' Get the SMS_SCI_Configuration, SMS_NETWORK_DISCOVERY section of the site control file.                    
    Query = "SELECT * FROM SMS_SCI_Configuration "       & _
    "WHERE ItemName = 'SMS_NETWORK_DISCOVERY' " & _
    "AND SiteCode = '" & siteCode & "'"
              
    ' Get the SMS_NETWORK_DISCOVERY properties.
    Set SCIComponentSet = swbemServices.ExecQuery(Query, ,wbemFlagForwardOnly Or wbemFlagReturnImmediately, swbemContext)
                       
    ' Only one instance is returned from the query.
    For Each SCIComponent In SCIComponentSet
    
        ' Loop through the array of embedded SMS_EmbeddedProperty instances.
        For Each vProperty In SCIComponent.Props
            
            ' Setting: Discovery Enabled
            If vProperty.PropertyName = "Discovery Enabled" Then
                wscript.echo " "
                wscript.echo vProperty.PropertyName
                wscript.echo "Current value: " &  vProperty.Value1               
                
                ' Modify the value.
                vProperty.Value1 = enableDisableDiscovery
                wscript.echo "New value:     " & enableDisableDiscovery
            End If
                            
         Next
         
         ' Update the component in your copy of the site control file. Get the path
         ' to the updated object, which could be used later to retrieve the instance.
          Set SCICompPath = SCIComponent.Put_(wbemChangeFlagUpdateOnly, swbemContext)

    Next
                          
    ' Commit the change to the actual site control file.
    Set InParams = swbemServices.Get("SMS_SiteControlFile").Methods_("CommitSCF").InParameters.SpawnInstance_
    InParams.SiteCode = siteCode
    swbemServices.ExecMethod "SMS_SiteControlFile", "CommitSCF", InParams, , swbemContext
      
    ' Release the copy of the site control file.
    swbemServices.Get("SMS_SiteControlFile").ReleaseSessionHandle swbemContext.Item("SessionHandle").Value

End Sub
public void ConfigureNetworkDiscoverySettings(WqlConnectionManager connection,
                                              string siteCode,
                                              string serverName,
                                              string enableDisableDiscovery)

{
    try
    {
        // Connect to SMS_SCI_Component, SMS_NETWORK_DISCOVERY section of the site control file.
        IResultObject siteDefinition = connection.GetInstance(@"SMS_SCI_Component.FileType=2,ItemType='Component',SiteCode='" + siteCode + "',ItemName='SMS_NETWORK_DISCOVERY|" + serverName + "'");

        // Create temporary copy of the embedded properties.
        Dictionary<string, IResultObject> embeddedProperties = siteDefinition.EmbeddedProperties;

        // Enumerate through the embedded properties and makes changes as needed.
        foreach (KeyValuePair<string, IResultObject> kvp in siteDefinition.EmbeddedProperties)
        {
            // Setting: Discovery Enabled
            if (kvp.Value.PropertyList["PropertyName"] == "Discovery Enabled")
            {
                Console.WriteLine();
                Console.WriteLine(kvp.Value.PropertyList["PropertyName"]);
                Console.WriteLine("Current value: " + kvp.Value.PropertyList["Value1"]);

                // Change value using the newDiscoveryEnabled value passed in. 
                embeddedProperties["Discovery Enabled"]["Value1"].StringValue = enableDisableDiscovery;
                Console.WriteLine("New value    : " + enableDisableDiscovery);
            }
        }

        // Store the settings that have changed.
        siteDefinition.EmbeddedProperties = embeddedProperties;

        // Save the settings. 
        siteDefinition.Put();
    }

    catch (SmsException ex)
    {
        Console.WriteLine();
        Console.WriteLine("Failed. Error: " + ex.InnerException.Message);
    }

    try
    {
        // Connect to SMS_SCI_Configuration, SMS_NETWORK_DISCOVERY section of the site control file.
        IResultObject siteDefinition = connection.GetInstance(@"SMS_SCI_Configuration.FileType=2,ItemType='Configuration',SiteCode='" + siteCode + "',ItemName='SMS_NETWORK_DISCOVERY'");

        // Create temporary copy of the embedded properties.
        Dictionary<string, IResultObject> embeddedProperties = siteDefinition.EmbeddedProperties;

        // Enumerate through the embedded properties and makes changes as needed.
        foreach (KeyValuePair<string, IResultObject> kvp in siteDefinition.EmbeddedProperties)
        {
            // Setting: Discovery Enabled
            if (kvp.Value.PropertyList["PropertyName"] == "Discovery Enabled")
            {
                Console.WriteLine();
                Console.WriteLine(kvp.Value.PropertyList["PropertyName"]);
                Console.WriteLine("Current value: " + kvp.Value.PropertyList["Value1"]);

                // Change value using the newDiscoveryEnabled value passed in. 
                embeddedProperties["Discovery Enabled"]["Value1"].StringValue = enableDisableDiscovery;
                Console.WriteLine("New value    : " + enableDisableDiscovery);
            }
        }

        // Store the settings that have changed.
        siteDefinition.EmbeddedProperties = embeddedProperties;

        //Save the settings. 
        siteDefinition.Put();
    }
    catch (SmsException ex)
    {
        Console.WriteLine("Failed. Error: " + ex.InnerException.Message);
        throw;
    }
}

The example method has the following parameters:

Parameter

Type

Description

connection

  • Managed: WqlConnectionManager

  • VBScript: SWbemServices

A valid connection to the SMS Provider.

siteCode

  • Managed: String

  • VBScript: String

The site code.

serverName

  • Managed: String

  • VBScript: String

The server name.

enableDisableDiscovery

  • Managed: String

  • VBScript: String

A value to enable or disable the discovery method.

Disabled - false

Enabled - true

Compiling the Code

This C# example requires:

Namespaces

System

System.Collections.Generic

System.Text

Microsoft.ConfigurationManagement.ManagementProvider

Microsoft.ConfigurationManagement.ManagementProvider.WqlQueryEngine

Assembly

adminui.wqlqueryengine

microsoft.configurationmanagement.managementprovider

Robust Programming

For more information about error handling, see About Configuration Manager Errors.

Security

For more information about securing Configuration Manager applications, see Securing Configuration Manager Applications.

See Also

Concepts

System Center Configuration Manager Software Development Kit
Configuration Manager Discovery
About Configuration Manager Discovery
About the Configuration Manager Site Control File
How to Read and Write to the Configuration Manager Site Control File by Using Managed Code
How to Read and Write to the Configuration Manager Site Control File by Using WMI
SMS_SCI_Component Server WMI Class
Configuration Manager Schedules
How to Create a Schedule Token