Enable exchange 2010 mailbox

∥☆過路亽.° 提交于 2019-12-06 06:16:13

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

}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!