【发布时间】:2014-12-22 12:39:15
【问题描述】:
我正在使用以下代码 sn-p 在域服务器上创建一个新的 AD 用户:
DirectoryEntry newUser = directoryEntry.Children.Add("CN=" + model.Account.FullName, "user");
if (model.Account.SamAccountName != null) newUser.Properties["sAMAccountName"].Value = model.Account.SamAccountName;
newUser.CommitChanges();
setUserPassword("CN=" + model.Account.FullName + "," + model.Account.Path, model.Account.Password);
newUser.RefreshCache();
if (model.Account.FirstName != null) newUser.Properties["givenName"].Add(model.Account.FirstName);
if (model.Account.LastName != null) newUser.Properties["sn"].Add(model.Account.LastName);
if (model.Account.MiddleName != null) newUser.Properties["initials"].Add(model.Account.MiddleName);
if (model.Account.UPNLogon != null && model.Account.DomainName != null) newUser.Properties["userPrincipalName"].Add(model.Account.UPNLogon + "@" + model.Account.DomainName);
if (model.Organization.DisplayName != null) newUser.Properties["displayName"].Add(model.Organization.DisplayName);
if (model.Organization.Email != null) newUser.Properties["mail"].Add(model.Organization.Email);
newUser.Properties["LockOutTime"].Value = 0; //unlock account
newUser.Properties["userAccountControl"].Value = 0x200; // enable account
newUser.CommitChanges();
string homeMDB = profile.Exchange13_Profile.ExchangeDB;
IMailboxStore mailbox;
try
{
IMailboxStore mailbox = (IMailboxStore)NewUser;
mailbox.CreateMailbox(sHomeMDB);
NewUser.CommitChanges();
}
catch (InvalidCastException e)
{
MessageBox.Show(e.Message.ToString());
}
以上代码成功创建新用户并在AD服务器上启用。但我无法创建/启用 Exchange 邮箱,因为IMailboxStore 命名空间需要cdoexm.dll。我试图在域控制器、邮箱服务器和客户端访问服务器上找到cdoexm.dll,但还是有规律的。
我知道另一种方法是使用 Powershell cmdlet,但我不想这样做。
现在准确地陈述我的问题:
- 如何添加COM
cdoexm.dll?或者 - 还有其他方法可以使用
IMailBoxStore吗?或者 - 除了 PowerShell 之外,还有其他方法可以启用 AD 用户的邮箱和 Lync 帐户吗?
前两个问题已得到解决,因为 CDOEXM 现在已从 Exchange 2010 及更高版本中淘汰。
【问题讨论】:
标签: c# active-directory exchange-server lync directoryentry