次の方法で共有


新しいコンピューターをConfiguration Managerにインポートする方法

新しいコンピューターをConfiguration Manager データベースに直接追加するには、クラス SMS_Siteで ImportMachineEntry メソッドを呼び出します。 これは、オペレーティング システムを、Configuration Managerによって自動的に検出されていないコンピューターに展開するために使用できます。

ヒント

Import-CMComputerInformation PowerShell コマンドレットを使用することもできます。

次の情報を指定する必要があります。

  • NETBIOS コンピューター名

  • MAC アドレス

  • SMBIOS GUID

注:

MAC アドレスは、Windows PE にドライバーがあるネットワーク アダプター用である必要があります。 MAC アドレスはコロン形式である必要があります。 たとえば、「 00:00:00:00:00:00 」のように入力します。 その他の形式では、クライアントがポリシーを受信できなくなります。

新しくインポートしたコンピューターをコレクションに追加する必要があります。 これにより、オペレーティング システムをコンピューターに展開するためのアドバタイズをすぐに作成できます。

新しいコンピューターを参照コンピューターに関連付けることができます。 詳細については、「Configuration Managerで 2 台のコンピューター間の関連付けを作成する方法」を参照してください。

新しいコンピューターを追加するには

  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 展開コンピューターの管理について