[英]How to Enable UMMailbox Exchange 2010
我在公司域中编写用于创建用户帐户的应用程序。 我们已经安装了Exchange 2010服务器,并且我需要为每个新的用户帐户电子邮件地址创建一个并启用统一按摩。 我创建电子邮件没有任何问题,但是当我尝试启用UMmailbox时出现错误,并且找不到我做错了什么。 在我的代码下面:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Management.Automation;
using System.Management.Automation.Runspaces;
using System.Collections.ObjectModel;
private string RunLocalExchangePowerShell(string script)
{
// create the runspace and load the snapin
RunspaceConfiguration rsConfig = RunspaceConfiguration.Create();
PSSnapInException snapInException = null;
Runspace runSpace = RunspaceFactory.CreateRunspace(rsConfig);
runSpace.Open();
rsConfig.AddPSSnapIn("Microsoft.Exchange.Management.PowerShell.E2010", out snapInException);
string DN = @"CN=User Name,OU=Company Users,DC=local,DC=contoso,DC=com";
Command enableUMMB = new Command("Enable-UMMailbox");
enableUMMB.Parameters.Add("Identity", DN);
enableUMMB.Parameters.Add("PinExpired", false);
enableUMMB.Parameters.Add("UMMailboxPolicy", "UM2 Default Policy");
enableUMMB.Parameters.Add("IgnoreDefaultScope");
Pipeline enableUMMailbox = runSpace.CreatePipeline();
enableUMMailbox.Commands.Add(enableUMMB);
Collection<PSObject> enabelUMmaiiboxResults = enableUMMailbox.Invoke();
enableUMMailbox.Dispose();
runSpace.Close();
}
错误如下:
“ Microsoft.Exchange.UM.UMCommon.UmGlobals”的类型初始值设定项引发了异常。
如果我在Powershell控制台中使用以上命令,则UMmailbow会创建任何问题。 在powerShell控制台中,我使用了以下字符串:
Enable-UMMailbox -Identity "CN=User Name,OU=Company Users,DC=local,DC=contoso,DC=com" -PinExpired $false -UMMailboxPolicy "UM2 Default Policy" -IgnoreDefaultScope
我仅找到一种使用Enable-UMMailbox Commandlet的方法。 我通过URI连接到Exchange服务器。 下面是我的代码的一部分:
string exchangePowershellRPSURI = "http://my.domain/powershell?serializationLevel=Full";
PSCredential credentials = (PSCredential)null;
//Provides the connection information that is needed to connect to a remote runspace
// Prepare the connection
WSManConnectionInfo connInfo = new WSManConnectionInfo((new Uri(exchangePowershellRPSURI)),
"http://schemas.microsoft.com/powershell/Microsoft.Exchange", credentials);
connInfo.AuthenticationMechanism = AuthenticationMechanism.Kerberos;
connInfo.SkipCACheck = true;
connInfo.SkipCNCheck = true;
connInfo.SkipRevocationCheck = true;
// Create the runspace where the command will be executed
Runspace runspace = RunspaceFactory.CreateRunspace(connInfo);
// Add the command to the runspace's pipeline
runspace.Open();
try
{
Command enableUMMB = new Command("Enable-UMMailbox");
enableUMMB.Parameters.Add("Identity", UserPrincipalName);
enableUMMB.Parameters.Add("PinExpired", false);
enableUMMB.Parameters.Add("UMMailboxPolicy", "UM2 Default Policy");
Pipeline enableUMMailboxPipiLine = runspace.CreatePipeline();
enableUMMailboxPipiLine.Commands.Add(enableUMMB);
enableUMMailboxPipiLine.Invoke();
}
catch (ApplicationException e)
{
MessageBox.Show("Unable to connect to UMMailbox.\n Error:\n" + e.Message,
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.