[英]C# Powershell - Exchange management {“Value cannot be null.\r\nParameter name: serverSettings”}
我想與通過C#項目安裝在計算機上的Microsoft.Exchange.Management.PowerShell.E2010
進行交互。
我的本地計算機是Windows Server 2012 R2 Standard,並且安裝了具有匯總更新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();
\\!/問題在最后一步, results = ps.Invoke();
引發System.Management.Automation.RemoteException
,並顯示消息"Value cannot be null.\\r\\nParameter name: serverSettings"
。
你們有什么主意嗎?
感謝您的時間。
在過去的幾天里,我一直在與這個斗爭。 我知道這個問題還有幾個月的時間了,但是我想我會分享我終於找到的解決方案。 在您的.config中,您需要在startup
標記useLegacyV2RuntimeActivationPolicy
屬性設置為true
。 像這樣:
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2"/>
</startup>
使用此工具,我可以在定位.NET 4.6.2時成功運行Get-Mailbox
命令。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.