如何启用 UMMailbox Exchange 2010
本文关键字:UMMailbox Exchange 2010 启用 何启用 | 更新日期: 2023-09-27 18:32:54
我编写用于在我们公司域中创建用户帐户的应用程序。我们已经安装了Exchange 2010服务器,我需要为每个新的用户帐户创建电子邮件地址并启用Unify Massaging。我创建电子邮件没有问题,但是当我尝试启用UM邮箱时,我遇到了错误,并且找不到我做错了什么。在我的代码下面:
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命令。我通过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);
}