2013-02-01 87 views
1

我有一個順序調用HA Exchange環境(單個開發主機上的一切工作正常)上的多個PowerShell命令的問題。只要它是關於Exchange命令,我通過管道多個命令(執行在同一個節點上)使用解決方法,一切都很好。我的代碼:Exchange 2010複製問題,而C#PowerShell調用多個命令

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

單個主機環境中不存在問題。 醫管局這樣,其他的命令在不同的主機上運行:

[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永久連接。 你有什麼解決方案嗎?

回答

0

你試試這個嗎?

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