private void CreateNewComputer(string computerName, string computerOUPath)
        {
            try
            {
                // Set default Directory OU Path
                PrincipalContext setOU = new PrincipalContext(ContextType.Domain, null, computerOUPath);

                // Create new Computer object
                ComputerPrincipal newComputerObject = new ComputerPrincipal(setOU, computerName, "password", enabled: true);

                // Set Extra Computer Info
                newComputerObject.DisplayName = computerName;

                // Save settings
                using (newComputerObject)
                {
                    newComputerObject.Save();
                }

                // Close Connection
                newComputerObject.Dispose();

            }
            catch (Exception ex)
            {

                Console.WriteLine("Some error to create computer object" + ex.Message);
                throw;
            }
        }
示例#2
0
 public void ComputerPrincipalConstructorTest()
 {
     ComputerPrincipal computer = new ComputerPrincipal(domainContext);
     computer.Dispose();
     Assert.Inconclusive("TODO: Implement code to verify target");
 }