Add a Computer Domain
-
Do any know how to impliment adding a computer to domain using C#. I know you have to import System.Directory.Services.dll Can you please help thanks CJ:)
Try something like the following:
string domain = ...;
string newComputer = ...;
string groupName = ...;// Connect to AD and get the computer container object
DirectoryEntry deDomain = new DirectoryEntry("WinNT://" + domain);
DirectoryEntry deNewComputer = new DirectoryEntry("WinNT://" + domain + "/" + newComputer + ", computer");// Connect to the group container and add the computer object
DirectoryEntry deGrp = deDomain.Children.Find(groupName, "Group");
if (deGrp.Name != null)
deGrp.Invoke("Add", new Object[]{deNewComputer.Path.ToString()});
deGrp.CommitChanges(); -
Try something like the following:
string domain = ...;
string newComputer = ...;
string groupName = ...;// Connect to AD and get the computer container object
DirectoryEntry deDomain = new DirectoryEntry("WinNT://" + domain);
DirectoryEntry deNewComputer = new DirectoryEntry("WinNT://" + domain + "/" + newComputer + ", computer");// Connect to the group container and add the computer object
DirectoryEntry deGrp = deDomain.Children.Find(groupName, "Group");
if (deGrp.Name != null)
deGrp.Invoke("Add", new Object[]{deNewComputer.Path.ToString()});
deGrp.CommitChanges();