【发布时间】:2021-12-27 15:39:45
【问题描述】:
我创建了一个工具箱来在各种管理系统(包括 Active Directory)中创建计算机。这个工具箱多年来一直完美无缺。自本月起,在 Active Directory 中创建计算机对象不再起作用。我仍在寻找原因,但似乎与域控制器上的补丁有关。 创建对象的用户没有任何更改。 当我使用以下命令手动创建具有用户凭据的客户端时,它可以正常工作。
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;
}
错误信息:
27.12.2021 16:19:46 System.UnauthorizedAccessException:访问被拒绝。
在 System.DirectoryServices.AccountManagement.ADStoreCtx.Insert(Principal p) 在 System.DirectoryServices.AccountManagement.Principal.Save() 在 C:\Temp\Win10Toolbox\Source\AZToolboxClient\MyClasses\ActiveDirectory.cs:line 71 中的 ClientToolbox.ActiveDirectory.createComputerAccount(Client computer)
非常感谢! 最好的祝福 伊尼克
【问题讨论】:
标签: c# active-directory