如何将新计算机导入Configuration Manager

通过在类SMS_Site中调用 ImportMachineEntry 方法,将新计算机直接添加到 Configuration Manager 数据库。 这可用于将作系统部署到尚未通过Configuration Manager自动发现的计算机。

提示

还可以使用 Import-CMComputerInformation PowerShell cmdlet。

必须提供以下信息:

  • NETBIOS 计算机名称

  • MAC 地址

  • SMBIOS GUID

注意

MAC 地址必须适用于在 Windows PE 中具有驱动程序的网络适配器。 MAC 地址必须采用冒号格式。 例如,00:00:00:00:00:00。 其他格式将阻止客户端接收策略。

应将新导入的计算机添加到集合。 这允许你立即创建用于将作系统部署到计算机的播发。

可以将新计算机与引用计算机相关联。 有关详细信息,请参阅如何在 Configuration Manager 中创建两台计算机之间的关联

添加新计算机

  1. 设置与 SMS 提供程序的连接。 有关详细信息,请参阅 SMS 提供程序基础知识

  2. 在类SMS_Site中调用 ImportMachineEntry 方法

  3. 将从 ImportMachineEntry 获取的资源标识符添加到集合。

示例

以下示例方法将新计算机添加到 Configuration Manager。 类SMS_Site中的 ImportMachineEntry 方法用于导入计算机。 然后,将计算机添加到自定义集合。 “所有系统”集合。

重要

在此示例的早期版本中,计算机已添加到“所有系统”集合中。 不再可以修改内置集合,请改用自定义集合。

有关调用示例代码的信息,请参阅调用Configuration Manager代码片段

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='ABC0000A'")

   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='ABC0000A'");
        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;
    }
}

示例方法具有以下参数:

参数 类型 说明
connection -管理: WqlConnectionManager
- VBScript: SWbemServices
- 与 SMS 提供程序的有效连接。
netBiosName -管理: String
- VBScript: String
- 计算机 NETBIOS 名称。
smBiosGuid -管理: String
- VBScript: String
计算机的 SMBIOS GUID。
MacAddress -管理: String
- VBScript: String
采用以下格式的计算机的 MAC 地址: 00:00:00:00:00:00

编译代码

C# 示例具有以下编译要求:

命名空间

System

System.Collections.Generic

Microsoft.ConfigurationManagement.ManagementProvider

Microsoft.ConfigurationManagement.ManagementProvider.WqlQueryEngine

Assembly

microsoft.configurationmanagement.managementprovider

adminui.wqlqueryengine

可靠编程

有关错误处理的详细信息,请参阅关于Configuration Manager错误

.NET Framework 安全性

有关保护Configuration Manager应用程序的详细信息,请参阅Configuration Manager基于角色的管理

另请参阅

类SMS_Site中的 ImportMachineEntry 方法关于 OS 部署计算机管理