[英]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.