【发布时间】:2013-04-15 18:31:47
【问题描述】:
我正在尝试以编程方式导出传输规则。
我的代码适用于 get-exchangeserver 和 get-TransportRule 等简单命令,但如果我尝试将命令导入规则赋予某个文件,则会出现错误,即给定命令无法识别为 cmdlet、脚本。
我的代码如下(我已尝试同时给予 windows 身份验证或用户身份验证谁是交换管理员):
WSManConnectionInfo connectionInfo = new WSManConnectionInfo(serverUri, SHELL_URI, creds);
try
{
using (Runspace rs = RunspaceFactory.CreateRunspace(connectionInfo))
{
PowerShell psh = PowerShell.Create();
psh.Runspace = rs;
rs.Open();
psh.AddCommand("$file = Export-TransportRuleCollection -ExportLegacyRules" +"Set-Content -Path " + @"C:\LegacyRules3.xml" + "-Value file.FileData -Encoding Byte");
psh.Invoke();
我使用的是 C# 和 Exchange Server 2010,PowerShell 版本是 1.0。远程操作系统是 Winodws 7。
知道我应该做什么更正吗?
【问题讨论】:
标签: c# powershell powershell-cmdlet