.net中,请问一下Exchange2010的邮箱数据库不能加服务器名?为什么?该怎么远程创建Exchange2010用户邮箱呢?
2007可以加“服务器名\\邮箱数据库"。
代码:
#region 创建邮箱账号
public bool NewMailbox(string name, string accountName, string pwd, string emailDomain, string organizationalUnit, string database)
{
string emailAdd = accountName + emailDomain;
if (this.IsExistMailBox(emailAdd))
{
throw new Exception("已经存在同名的邮箱");
}
try
{
PSSnapInException PSException = null;
RunspaceConfiguration runspaceConf = RunspaceConfiguration.Create();
runspaceConf.AddPSSnapIn("Microsoft.Exchange.Management.PowerShell.E2010", out PSException);
Runspace runspace = RunspaceFactory.CreateRunspace(runspaceConf);
runspace.Open();
Pipeline pipeline = runspace.CreatePipeline();
Command command = new Command("New-Mailbox");
char[] passwordChars = pwd.ToCharArray();
SecureString password = new SecureString();
foreach (char c in passwordChars)
{
password.AppendChar(c);
}
command.Parameters.Add("Name", name);//姓名
command.Parameters.Add("UserPrincipalName", emailAdd);//邮箱地址
command.Parameters.Add("SamAccountName", accountName);//登录名
command.Parameters.Add("Password", password);//密码
command.Parameters.Add("OrganizationalUnit", organizationalUnit);//组织单元
command.Parameters.Add("Database", database);//数据库
pipeline.Commands.Add(command);
Collection<PSObject> result = pipeline.Invoke();
runspace.Close();
return this.IsExistMailBox(emailAdd);
}
catch (Exception ex)
{
throw ex;
}
}
#endregion