Freigeben über


How to Import a New Computer into Configuration Manager

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 add a new computer directly to the Microsoft System Center Configuration Manager 2007 database by calling the ImportMachineEntry Method in Class SMS_Site. This can be used to deploy operating systems to computers that have not yet been discovered automatically by Configuration Manager 2007.

You must provide the following information:

  • NETBIOS computer name

  • MAC address

  • SMBIOS GUID

Note

The MAC address must be for a network adapter that has a driver in Windows PE. The MAC address must be in colon format. For example, 00:00:00:00:00:00. Other formats will prevent the client from receiving policy.

You should add a newly imported computer to a collection. This allows you to immediately create advertisements for deploying operating systems to the computer.

You can associate a new computer with a reference computer. For more information, see How to Create an Association Between Two Computers in Configuration Manager.

To add a new computer

  1. Set up a connection to the SMS Provider. For more information, see About the SMS Provider in Configuration Manager.

  2. Call the ImportMachineEntry Method in Class SMS_Site.

  3. Add the resource identifier you get from ImportMachineEntry to a collection.

Example

The following example method adds a new computer to Configuration Manager. The ImportMachineEntry Method in Class SMS_Site is used to import the computer. Then, the computer is added to the "All Systems" collection.

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

Sub AddNewComputer (connection, netBiosName, smBiosGuid, macAddress)

    Dim inParams
    Dim outParams
    Dim siteClass
    Dim collection
    Dim collectionRule
    
    If (IsNull(smBiosGuid) = True) And (IsNull(macAddress) = True) Then
        WScript.Echo "smBiosGuid or macAddress must be defined"
        Exit Sub
    End If     

    If IsNull(macAddress) = False Then
        macAddress = Replace(macAddress,"-",":")
    End If    
    
    ' Obtain an InParameters object specific
    ' to the method.
    
    Set siteClass = connection.Get("SMS_Site")
    Set inParams = siteClass.Methods_("ImportMachineEntry"). _
        inParameters.SpawnInstance_()


    ' Add the input parameters.
    inParams.Properties_.Item("MACAddress") =  macAddress
    inParams.Properties_.Item("NetbiosName") =  netBiosName
    inParams.Properties_.Item("OverwriteExistingRecord") =  False
    inParams.Properties_.Item("SMBIOSGUID") =  smBiosGuid

    ' Add the computer.
    Set outParams = connection.ExecMethod("SMS_Site", "ImportMachineEntry", inParams)

   
   ' Add the computer to the all systems collection.
   set collection = connection.Get("SMS_Collection.CollectionID='SMS00001'")
   
   set collectionRule=connection.Get("SMS_CollectionRuleDirect").SpawnInstance_
   
   collectionRule.ResourceClassName="SMS_R_System"
   collectionRule.ResourceID= outParams.ResourceID
       
   collection.AddMembershipRule collectionRule

End Sub
public int AddNewComputer(
    WqlConnectionManager connection, 
    string netBiosName, 
    string smBiosGuid, 
    string macAddress)
{
    try
    {
        if (smBiosGuid == null && macAddress == null)
        {
            throw new ArgumentNullException("smBiosGuid or macAddress must be defined");
        }

        // Reformat macAddress to : separator.
        if (string.IsNullOrEmpty(macAddress) == false)
        {
            macAddress = macAddress.Replace("-", ":");
        }

        // Create the computer.
        Dictionary<string, object> inParams = new Dictionary<string, object>();
        inParams.Add("NetbiosName", netBiosName);
        inParams.Add("SMBIOSGUID", smBiosGuid);
        inParams.Add("MACAddress", macAddress);
        inParams.Add("OverwriteExistingRecord", false);

        IResultObject outParams = connection.ExecuteMethod(
            "SMS_Site",
            "ImportMachineEntry",
            inParams);

        // Add to All System collection.
        IResultObject collection = connection.GetInstance("SMS_Collection.collectionId='SMS00001'");
        IResultObject collectionRule = connection.CreateEmbeddedObjectInstance("SMS_CollectionRuleDirect");
        collectionRule["ResourceClassName"].StringValue = "SMS_R_System";
        collectionRule["ResourceID"].IntegerValue = outParams["ResourceID"].IntegerValue;

        Dictionary<string, object> inParams2 = new Dictionary<string, object>();
        inParams2.Add("collectionRule", collectionRule);

        collection.ExecuteMethod("AddMembershipRule", inParams2);

        return outParams["ResourceID"].IntegerValue;
    }
    catch (SmsException e)
    {
        Console.WriteLine("failed to add the computer" + e.Message);
        throw;
    }
}

The example method has the following parameters:

Parameter

Type

Description

connection

  • Managed: WqlConnectionManager

  • VBScript: SWbemServices

  • A valid connection to the SMS Provider.

netBiosName

  • Managed: String

  • VBScript: String

  • The computer NETBIOS name.

smBiosGuid

  • Managed: String

  • VBScript: String

The SMBIOS GUID for the computer.

MacAddress

  • Managed: String

  • VBScript: String

The MAC address for the computer in the following format: 00:00:00:00:00:00.

Compiling the Code

The C# example has the following compilation requirements:

Namespaces

System

System.Collections.Generic

Microsoft.ConfigurationManagement.ManagementProvider

Microsoft.ConfigurationManagement.ManagementProvider.WqlQueryEngine

Assembly

microsoft.configurationmanagement.managementprovider

adminui.wqlqueryengine

Robust Programming

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

Security

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

See Also

Reference

ImportMachineEntry Method in Class SMS_Site