启用Exchange 2010邮箱 [英] Enable exchange 2010 mailbox

查看:508
本文介绍了启用Exchange 2010邮箱的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从C#code的Exchange 2010服务器上创建/启用邮箱。
我到处看看我看到使用code的人如下图所示。

不过,我得到以下错误:

启用邮箱一词未被识别为cmdlet,函数,脚本文件或可操作的程序的名称。检查名称的拼写,或者是否包含路径,验证路径是否正确,然后重试。

我在做什么错了?

  SecureString的密码=新SecureString的();        字符串str_password =MYPASSWORD;
        字符串的用户名=名为myUsername;        // FQDN是ofcourse我们的Exchange服务器的(完全限定)名称..
        字符串liveIdconnectionUri =?HTTP:// FQDN / Powershell的serializationLevel =完整;        的foreach(在str_password焦X)
        {
            password.AppendChar(X);
        }        PSCredential的凭据=新PSCredential的(用户名,密码);        WSManConnectionInfo connectionInfo =新WSManConnectionInfo((新的URI(liveIdconnectionUri)),http://schemas.microsoft.com/powershell/Microsoft.Exchange,证书);
        connectionInfo.AuthenticationMechanism = AuthenticationMechanism.Default;        运行空间运行空间= System.Management.Automation.Runspaces.RunspaceFactory.CreateRunspace(connectionInfo);
        PowerShell中的PowerShell = PowerShell.Create();
        PSCommand命令=新PSCommand();        command.AddCommand(启用邮箱);
        command.AddParameter(身份,日本鬼子domainname.ltd/OUName/TestAcc);
        command.AddParameter(别名,TestAccJap);
        command.AddParameter(数据库,DB-名称);        powershell.Commands =命令;        尝试
        {
            runspace.Open();
            powershell.Runspace =运行空间;
            powershell.Invoke();
        }
        赶上(异常前)
        {
            Console.WriteLine(ex.Message);
        }
        最后
        {
            runspace.Dispose();
            运行空间= NULL;
            powershell.Dispose();
            PowerShell的= NULL;
        }


解决方案

这可能是一个PowerShell相关的错误。如果从远程计算机(不是Exchange服务器)运行code,您必须启用有问题的用户远程PowerShell访问,并确保防火墙(S)允许端口80到Exchange服务器的连接。在Exchange Server:

 设置用户名-Identity $ -RemotePowershellEnabled真

用户也可以成为交换管理中的作用,允许创建邮箱的成员。

如果您使用的是负载balanser和/或有一个DAG您可能需要设立一个备用服务帐户启用Kerberos身份验证。请参见 http://technet.microsoft.com/en-us/library/ff808313。 ASPX 的详情。我不得不让本作在我的环境中code运行。我修改了code位,只是测试,如果我能够运行Exchange PowerShell命令。下面code与USERIDENT用户如果成功的全称响应。

 静态无效的主要(字串[] args)
{
    SecureString的密码=新SecureString的();
    字符串str_password =PASS;
    字符串的用户名=域\\\\用户;    // FQDN是ofcourse我们的Exchange服务器的(完全限定)名称..
    字符串liveIdconnectionUri =?HTTP:// SERVERFQDN / Powershell的serializationLevel =完整;
    的foreach(在str_password焦X)
    {
        password.AppendChar(X);
    }
    PSCredential的凭据=新PSCredential的(用户名,密码);
    WSManConnectionInfo connectionInfo =新WSManConnectionInfo((新的URI(liveIdconnectionUri)),http://schemas.microsoft.com/powershell/Microsoft.Exchange,证书);
    运行空间运行空间= NULL;
    PowerShell中的PowerShell = PowerShell.Create();
    PSCommand命令=新PSCommand();
    command.AddCommand(获取邮箱);
    command.AddParameter(身份,USERIDENT);
    powershell.Commands =命令;
    尝试
    {
        connectionInfo.AuthenticationMechanism = AuthenticationMechanism.Default;
        运行空间= System.Management.Automation.Runspaces.RunspaceFactory.CreateRunspace(connectionInfo);
        runspace.Open();
        powershell.Runspace =运行空间;
        收集和LT; PSObject> commandResults = powershell.Invoke< PSObject>();
        的foreach(在commandResults PSObject结果)
        {
            Console.WriteLine(result.ToString());
        }
    }
    赶上(异常前)
    {
        Console.WriteLine(ex.Message);
    }
    最后
    {
        runspace.Dispose();
        运行空间= NULL;
        powershell.Dispose();
        PowerShell的= NULL;
    }}

I'm trying to create/enable a mailbox on an exchange 2010 server from C# code. Everywhere I look I see people using the code shown below.

However I get the following error:

The term 'Enable-Mailbox' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

What am I doing wrong?

        SecureString password = new SecureString();

        string str_password = "myPassword";
        string username = "myUsername";

        //FQDN is ofcourse the (fully qualified) name of our exchange server..
        string liveIdconnectionUri = "http://FQDN/Powershell?serializationLevel=Full";

        foreach (char x in str_password)
        {
            password.AppendChar(x);
        }

        PSCredential credential = new PSCredential(username, password);

        WSManConnectionInfo connectionInfo = new WSManConnectionInfo((new Uri(liveIdconnectionUri)), "http://schemas.microsoft.com/powershell/Microsoft.Exchange", credential);
        connectionInfo.AuthenticationMechanism = AuthenticationMechanism.Default;

        Runspace runspace = System.Management.Automation.Runspaces.RunspaceFactory.CreateRunspace(connectionInfo);
        PowerShell powershell = PowerShell.Create();
        PSCommand command = new PSCommand();

        command.AddCommand("Enable-Mailbox");
        command.AddParameter("Identity", "domainname.ltd/OUName/TestAcc Jap");
        command.AddParameter("Alias", "TestAccJap");
        command.AddParameter("Database", "DB-Name");

        powershell.Commands = command;

        try
        {
            runspace.Open();
            powershell.Runspace = runspace;
            powershell.Invoke();
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }
        finally
        {
            runspace.Dispose();
            runspace = null;
            powershell.Dispose();
            powershell = null;
        }

解决方案

This is probably a powershell related error. If you are running the code from a remote machine (not the exchange server), you have to enable remote powershell access for the user in question and make sure the firewall(s) allows connections to the exchange server on port 80. On the exchange server:

Set-User –identity username –RemotePowershellEnabled $True

The user also has to be a member of an exchange management role allowing mailbox creation.

If you are using a load balanser and/or have a DAG you may have to set up an Alternate Service Account to enable Kerberos authentication. See http://technet.microsoft.com/en-us/library/ff808313.aspx for details. I had to enable this to make the code run in my environment. I modified the code a bit to just test if I was able to run exchange powershell commands. The following code responds with the full name of the USERIDENT user if successful.

static void Main(string[] args)
{
    SecureString password = new SecureString();
    string str_password = "PASS";
    string username = "domain\\user";

    //FQDN is ofcourse the (fully qualified) name of our exchange server.. 
    string liveIdconnectionUri = "http://SERVERFQDN/Powershell?serializationLevel=Full";
    foreach (char x in str_password)
    {
        password.AppendChar(x);
    }
    PSCredential credential = new PSCredential(username, password);
    WSManConnectionInfo connectionInfo = new WSManConnectionInfo((new Uri(liveIdconnectionUri)), "http://schemas.microsoft.com/powershell/Microsoft.Exchange", credential);
    Runspace runspace = null;
    PowerShell powershell = PowerShell.Create();
    PSCommand command = new PSCommand();
    command.AddCommand("Get-Mailbox");
    command.AddParameter("Identity", "USERIDENT");
    powershell.Commands = command;
    try
    {
        connectionInfo.AuthenticationMechanism = AuthenticationMechanism.Default;
        runspace = System.Management.Automation.Runspaces.RunspaceFactory.CreateRunspace(connectionInfo);
        runspace.Open();
        powershell.Runspace = runspace;
        Collection<PSObject> commandResults = powershell.Invoke<PSObject>();
        foreach (PSObject result in commandResults)
        {
            Console.WriteLine(result.ToString());
        }
    }
    catch (Exception ex)
    {
        Console.WriteLine(ex.Message);
    }
    finally
    {
        runspace.Dispose();
        runspace = null;
        powershell.Dispose();
        powershell = null;
    } 

}

这篇关于启用Exchange 2010邮箱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆