i would like to import a computer to a specific SCCM-collection.
I've found this method on the msdn:
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;
}
}
Now, I try to call it with a button event:
private void button2_Click(object sender, EventArgs e)
{
AddNewComputer(PcNameBox.Text, MacAdrBox, PcNameBox.Text, CollectionDropDown.Text);
}
But I'm sorry, I don't no how to call the WQLConnectionManager on this point?! I know the object must be preset before "PcNameBox.Text". That's all :(
On another event, I call it like this:
SmsNamedValuesDictionary namedValues = new SmsNamedValuesDictionary();
WqlConnectionManager connection = new WqlConnectionManager(namedValues);
connection.Connect(PrimarySiteServer);
But this Method is struggling me. (It's only a hobby, pleave be indulgent)
Thanks in advance for a hint...
Chris