启用计算机添加到Active Directory OU [英] Add enabled Computer to Active Directory OU

查看:256
本文介绍了启用计算机添加到Active Directory OU的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要一台电脑编程方式添加到我公司的Active Directory中。结果
我这么久,现在正在寻找在互联网上,但我无法找到一个解决方案。

I am trying to programmatically add a computer to the Active Directory of my company.
I was searching the internet for so long now, but i couldn't find a solution.

我的代码:

DirectoryEntry dirEntry = new DirectoryEntry("LDAP://OU=ou2example,OU=ou1example,DC=site,DC=company,DC=com");
dirEntry.Username = "username";
dirEntry.Password = "password";
DirectoryEntry newComputer = dirEntry.Children.Add("CN=" + ComputerName, "computer");
newComputer.CommitChanges();



我的问题:

My problem:

计算机是添加到Active Directory。但它被标记为禁用。

The computer is added to the Active Directory. But it is flagged as disabled.

我试着以下,以使计算机:

I tried to following to enable the computer:

newComputer.Properties["userAccountControl"].Value = 0x200;



不过,我得到一个DirectoryServicesCOMException - >服务器无法完成请求

But I get an DirectoryServicesCOMException --> The server can not complete the request.

newComputer.Properties["Enabled"].Value = true;



不过,我得到一个DirectoryServicesCOMException - >请求的操作不满足至少一个约束即是此对象类的条件。

But I get an DirectoryServicesCOMException --> The requested operation does not satisfy at least one constraint that is for this object class condition.

请注意,例外是从德国翻译成英语!

Please note that the exceptions are translated from german to english!

感谢您的帮助!

推荐答案

我觉得有两件事情是错误的,但它已经,因为我不喜欢这样,所以我也许错了什么很长一段时间。 ..

I think two things can be wrong but it's been a long time since I did anything like this so I maybe wrong...

首先,当你设置 userAccountControl的标志?我似乎记得,你应该为新的条目后的CommitChanges 做到这一点。所以像这样的:

First of all, when do you set the userAccountControl flag? I seem to remember you should do this after the CommitChanges for the new entry. So like this:

DirectoryEntry newComputer =
    dirEntry.Children.Add("CN=" + ComputerName, "computer");
newComputer.CommitChanges();
newComputer.Properties["userAccountControl"].Value = 0x200;
newComputer.CommitChanges();



其次,可以尝试设置的 UF_WORKSTATION_TRUST_ACCOUNT 标志( 0×1000 ),而不是 UF_NORMAL_ACCOUNT 为0x200 )。

您还可以检查是否 sAMAccountType 是 SAM_MACHINE_ACCOUNT 0x30000001 )。我想这应该是自动的,但不伤害检查。

Can you also check whether the sAMAccountType of the entry is SAM_MACHINE_ACCOUNT (0x30000001). I think this should be automatic but doesn't hurt to check.

这篇关于启用计算机添加到Active Directory OU的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆