我创建了一个工具箱,用于在各种管理系统(包括Active Directory)中创建计算机。多年来,这个工具箱一直工作完美。自本月起,在Active Directory中创建计算机对象不再有效。我仍在寻找原因,但似乎与补丁有关
KB5008383
在域控制器上。
Microsoft Update Information
去年2021 12月,我遇到了同样的问题,也与微软的补丁有关,我可以在SAMAccountName的末尾用$来修复这个问题。
创建对象的用户没有任何更改。
当我使用以下命令手动创建具有用户凭据的客户端时,它工作正常。
New-ADComputer -Name NB89991 -Path "ou=nb,ou=w10,ou=clt,ou=tier2,ou=central,dc=xy-dom,dc=xy,dc=ch" -SAMAccountName NB89991
你知道我的代码有什么问题吗?
public Boolean createComputerAccount(Client computer){
Boolean returnValue = true;
try {
if (!existComputer(computer))
{
PrincipalContext oPrincipalContext = GetPrincipalContext(computer.ou);
ComputerPrincipal computerPrincipal = new ComputerPrincipal(oPrincipalContext);
computerPrincipal.SamAccountName = computer.name + "$";
computerPrincipal.Name = computer.name;
if (!(computer.adDescription == "")) {
computerPrincipal.Description = computer.adDescription;
}
MessageBox.Show(computerPrincipal.SamAccountName, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
MessageBox.Show(computerPrincipal.Name, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
computerPrincipal.Enabled = true;
computerPrincipal.Save();
returnValue = true;
}
else {
returnValue = false;
}
}catch (Exception e){
errorMessage = "Creating a computer in Active Directory failed!\r\nPlease contact the ITCM TEAM or check the Logfile:\r\n (c:\\temp\\ClientToolbox.log).";
createErrorMessage(errorMessage, e);
returnValue = false;
}
return returnValue;
}
public PrincipalContext GetPrincipalContext(string sOU) {
PrincipalContext oPrincipalContext = new PrincipalContext(ContextType.Domain, domain, sOU, ContextOptions.SimpleBind, ntUser, ntUserPWD);
return oPrincipalContext;
}
错误消息:
2022年5月27日上午11:58:32系统。UnauthorizedAccessException:访问权限为
否认。
在
系统DirectoryServices。会计管理。ADStoreCtx。插入(委托人
p) at系统。DirectoryServices。会计管理。最重要的保存()
在ClientToolbox。ActiveDirectory。createComputerAccount(客户端
计算机)