Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
c#powershell调用多个命令时出现Exchange 2010复制问题_C#_Powershell_Exchange Server 2010 - Fatal编程技术网

c#powershell调用多个命令时出现Exchange 2010复制问题

c#powershell调用多个命令时出现Exchange 2010复制问题,c#,powershell,exchange-server-2010,C#,Powershell,Exchange Server 2010,我在HA Exchange环境(在单个开发主机上,一切正常)上顺序调用多个powershell命令时遇到问题。只要它只是关于Exchange命令,我就通过管道传输多个命令(在同一节点上执行)来使用变通方法,一切都很好。我的代码: string casUri = "cas1.srv.net/Powershell?serializationLevel=Full"; string credentialUserName = "User"; string credentialUserPassword =

我在HA Exchange环境(在单个开发主机上,一切正常)上顺序调用多个powershell命令时遇到问题。只要它只是关于Exchange命令,我就通过管道传输多个命令(在同一节点上执行)来使用变通方法,一切都很好。我的代码:

string casUri = "cas1.srv.net/Powershell?serializationLevel=Full";
string credentialUserName = "User";
string credentialUserPassword = "secret";
string newOU = "thenewou";
string baseOU = "OU=root,DC=srv,DC=net";         
        System.Security.SecureString passwd = new System.Security.SecureString();
        foreach (char c in credentialUserPassword) {
            passwd.AppendChar(c);
        }
        PSCredential credential = new PSCredential(credentialUserName, passwd);

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

        connectionInfo.AuthenticationMechanism = AuthenticationMechanism.Default;
        runspacePool = RunspaceFactory.CreateRunspacePool(1, 5, connectionInfo);
        runspacePool.Open();

        powershell = PowerShell.Create();
        Command command;
            command = new PSCommand();
            command.AddCommand("New-ADOrganizationalUnit");
            command.AddParameter("Path", baseOU);
            command.AddParameter("Name", newOu);
            command.AddParameter("DisplayName", "My new OU");
            powershell.Commands = command;
        powershell.Invoke();

        // ... another AD commands: Set-ADForest, New-AcceptedDomain (work fine)
        // v--- trouble
            command = new PSCommand();
            command.AddCommand("New-GlobalAddressList");
            command.AddParameter("Name", "GAL.Name");
            command.AddParameter("RecipientContainer", newOu + "," baseOU);
            powershell.Commands = command;
        powershell.Invoke();
在单主机环境中不存在此问题。 在这样的HA上,另一个命令在不同的主机上运行:

   [myApp]---[CAS load balancer]---[CAS-1..CAS-N]---[EX-1..EX-N]
这会导致一个异常:

 Active Directory operation failed on DC2.srv.net. This error is not retriable.          
 Additional information: The name reference is invalid.
 This may be caused by replication latency between Active Directory domain controllers.
 Active directory response: 000020B5: AtrErr: DSID-03152804, #1:
            0: 000020B5: DSID-03152804, problem 1005 (CONSTRAINT_ATT_TYPE), data 0, Att 9b7f0292 (msExchSearchBase)
我不知道如何为几个命令强制使用单个远程shell进行持久连接。 你有什么解决办法吗?

你试过这个吗

command.AddParameter("DomainController", "Your Domain Contorller FQDN");