【问题标题】:How to Enable UMMailbox Exchange 2010如何启用 UMMailbox Exchange 2010
【发布时间】:2015-01-19 16:12:44
【问题描述】:

我编写了在我们公司域中创建用户帐户的应用程序。我们已经安装了 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

【问题讨论】:

    标签: c# exchange-server-2010


    【解决方案1】:

    我只找到了一种使用 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);
                    }
    

    【讨论】:

      猜你喜欢
      • 2012-01-11
      • 1970-01-01
      • 1970-01-01
      • 2022-08-10
      • 2011-08-27
      • 1970-01-01
      • 2013-11-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多