繁体   English   中英

与.Net交换管理Powershell

[英]Exchange Management Powershell with .Net

为什么我收到此例外:

System.Management.Automation.CommandNotFoundException: The term new-storagegroup....

相关代码:

RunspaceConfiguration rsConfig = RunspaceConfiguration.Create();
PSSnapInException snapInException = null;
PSSnapInInfo info = rsConfig.AddPSSnapIn("Microsoft.Exchange.Management.PowerShell.Admin", out snapInException);
Runspace myRunSpace = RunspaceFactory.CreateRunspace(rsConfig);
myRunSpace.Open();

//Create pipeline and feed it the script text
Pipeline pipeline = myRunSpace.CreatePipeline();

string strScript = "new-storagegroup -Server KINGKONG"
    + " -LogFolderPath c:\\rsg\\logs -Name RecoveryGroup -SystemFolderPath c:\\rsg\\data -Recovery";

//Create an instance of the Command class by using the name of the cmdlet that you want to run
Command myCommand = new Command(strScript);

//Add the command to the Commands collection of the pipeline.
pipeline.Commands.Add(myCommand);

Collection<PSObject> results = pipeline.Invoke();

请改用pipeline.Commands.AddScript(strScript) Command对象只需要Cmdlet,例如“New-StorageGroup”。 然后,您将使用返回的Command对象的Parameters集合来添加参数。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM