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