简体   繁体   中英

How to Enable UMMailbox Exchange 2010

I write application for creating User account in our company domain. We have installed Exchange 2010 server , and I need create for each new User account e-mail address and enable Unify Massaging. I create e-mail without problem, but when I try to enable UMmailbox I got an error, and could not found what I do wrong. Below part of my code:

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();
    }

The error is following:

The type initializer for 'Microsoft.Exchange.UM.UMCommon.UmGlobals' threw an exception.

If I use command above in Powershell console UMmailbow created whithout any problem. In powerShell console i used following string:

Enable-UMMailbox -Identity "CN=User Name,OU=Company Users,DC=local,DC=contoso,DC=com" -PinExpired $false -UMMailboxPolicy "UM2 Default Policy" -IgnoreDefaultScope

I have found only one way how to use Enable-UMMailbox commandlet. I connect to Exchange server through URI. Bellow part of my code:

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);
                }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM