You add a new computer directly to the System Center 2012 Configuration Manager 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 System Center 2012 Configuration Manager.
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
-
Set up a connection to the SMS Provider. For more information, see About the SMS Provider in Configuration Manager.
-
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.
Visual Basic Script | Copy Code |
---|---|
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 |
C# | Copy Code |
---|---|
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 |
|
|
netBiosName |
|
|
smBiosGuid |
|
The SMBIOS GUID for the computer. |
MacAddress |
|
The MAC address for the computer in the following format:
|
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 Securing Configuration Manager Applications.