【发布时间】:2012-03-27 09:37:58
【问题描述】:
我正在尝试从 2010 Exchange 服务器获取较低的存储,该函数将在 WCF 容器中运行。
我面临的问题是我无法在管道中运行多个 PowerShell 命令。
我尝试了以下方法(基于此,how to invoke the powershell command with "format-list" and "out-file" pipeline from c#?):
string strCommand = @"Get-MailboxDatabase -Status | select ServerName,Name,DatabaseSize | Sort-Object DatabaseSize";
string CommandLine = string.Format("&{{{0}}}", strCommand);
pipeLine.Commands.AddScript(CommandLine);
但我明白了:
未处理的异常:System.Management.Automation.RemoteException:在受限语言模式或数据部分中不允许使用脚本块文字。
我也试过了,
Command getMailbox = new Command("Get-MailboxDatabase");
getMailbox.Parameters.Add("Status", null);
Command sort = new Command("Sort-Object");
pipeLine.Commands.Add(getMailbox);
pipeLine.Commands.Add(sort);
Collection<PSObject> commandResults = pipeLine.Invoke();
但不是运气:
未处理的异常:System.Management.Automation.RemoteException:术语“排序对象”未被识别为 cmdlet 的名称
我想知道是否应该使用多个管道(每个 cmdlet 一个管道),但我不确定。
【问题讨论】:
标签: c# powershell exchange-server-2010