我想通過C#項目與我的機器上安裝的Microsoft.Exchange.Management.PowerShell.E2010
進行交互。C#Powershell - Exchange管理{「值不能爲空。 r nParameter name:serverSettings」}
我的本地計算機是Windows Server 2012 R2標準版,安裝了彙總更新14的Exchange Server 2010 SP3。
我使用的是4.5的.NET Framework(降級到舊版本是不可能的)
WSManConnectionInfo connectionInfo = new WSManConnectionInfo();
connectionInfo.OperationTimeout = 4 * 60 * 1000; // 4 minutes.
connectionInfo.OpenTimeout = 1 * 60 * 1000; // 1 minute.
Runspace runspace = RunspaceFactory.CreateRunspace(connectionInfo);
runspace.Open();
using (PowerShell ps = PowerShell.Create())
{
ps.Runspace = runspace;
ps.AddCommand("Add-PsSnapIn");
ps.AddArgument("Microsoft.Exchange.Management.PowerShell.E2010");
var results = ps.Invoke();
try
{
ps.AddCommand("Get-MailBox");
results = ps.Invoke();
}
catch (Exception e)
{
}
}
runspace.Close();
- 我打開遠程shell會話(針對性我的本地機器上)。
- 添加Exchange管理PsSnapIn,以便訪問交換命令。
- 最後我執行我的Exchange管理命令。
\!/問題是在最後一步,results = ps.Invoke();
拋出與消息"Value cannot be null.\r\nParameter name: serverSettings"
一個System.Management.Automation.RemoteException
。
你們有什麼想法嗎?
謝謝你的時間。
謝謝,我可以試試! –