【发布时间】:2016-07-26 20:52:24
【问题描述】:
我想与通过 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();
- 我打开了一个远程 shell 会话(针对我的本地计算机)。
- 添加 Exchange 管理 PsSnapIn,以便访问交换命令。
- 最后我执行了我的 Exchange 管理命令。
\!/ 问题出现在最后一步,results = ps.Invoke(); 抛出 System.Management.Automation.RemoteException 和消息 "Value cannot be null.\r\nParameter name: serverSettings"。
你们有什么想法吗?
感谢您的宝贵时间。
【问题讨论】:
标签: c# powershell exchange-server exchange-server-2010