Dela via


Importera en ny dator till Configuration Manager

Du lägger till en ny dator direkt i Configuration Manager-databasen genom att anropa metoden ImportMachineEntry i klass SMS_Site. Detta kan användas för att distribuera operativsystem till datorer som ännu inte har identifierats automatiskt av Configuration Manager.

Tips

Du kan också använda PowerShell-cmdleten Import-CMComputerInformation .

Du måste ange följande information:

  • NETBIOS-datornamn

  • MAC-adress

  • SMBIOS GUID

Obs!

MAC-adressen måste vara för ett nätverkskort som har en drivrutin i Windows PE. MAC-adressen måste vara i kolonformat. Till exempel 00:00:00:00:00:00. Andra format förhindrar att klienten tar emot principen.

Du bör lägga till en nyimporterad dator i en samling. På så sätt kan du omedelbart skapa annonser för distribution av operativsystem till datorn.

Du kan associera en ny dator med en referensdator. Mer information finns i Skapa en association mellan två datorer i Configuration Manager.

Så här lägger du till en ny dator

  1. Konfigurera en anslutning till SMS-providern. Mer information finns i grunderna för SMS-provider.

  2. Anropa metoden ImportMachineEntry i klass SMS_Site.

  3. Lägg till den resursidentifierare som du får från ImportMachineEntry till en samling.

Exempel

Följande exempelmetod lägger till en ny dator i Configuration Manager. ImportMachineEntry-metoden i klass SMS_Site används för att importera datorn. Sedan läggs datorn till i en anpassad samling. Samlingen "Alla system".

Viktigt

I den tidigare versionen av det här exemplet lades datorn till i samlingen "Alla system". Det går inte längre att ändra de inbyggda samlingarna. Använd en anpassad samling i stället.

Information om hur du anropar exempelkoden finns i Anropa Configuration Manager kodfragment.

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;  
    }  
}  

Exempelmetoden har följande parametrar:

Parameter Typ Beskrivning
connection -Hanterade: WqlConnectionManager
– VBScript: SWbemServices
– En giltig anslutning till SMS-providern.
netBiosName -Hanterade: String
-Vbscript: String
– Datorns NETBIOS-namn.
smBiosGuid -Hanterade: String
-Vbscript: String
SMBIOS GUID för datorn.
MacAddress -Hanterade: String
-Vbscript: String
MAC-adressen för datorn i följande format: 00:00:00:00:00:00.

Kompilera koden

C#-exemplet har följande kompileringskrav:

Namnområden

System

System.Collections.Generic

Microsoft. ConfigurationManagement.ManagementProvider

Microsoft. ConfigurationManagement.ManagementProvider.WqlQueryEngine

Församlingen

microsoft.configurationmanagement.managementprovider

adminui.wqlqueryengine

Robust programmering

Mer information om felhantering finns i Om Configuration Manager fel.

.NET Framework Säkerhet

Mer information om hur du skyddar Configuration Manager program finns i Configuration Manager rollbaserad administration.

Se även

ImportMachineEntry-metod i klass SMS_Site
Om datorhantering för operativsystemdistribution