3
爲什麼我收到此異常:Exchange管理PowerShell和淨
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();
我試着使用AddScript來代替'New-Mailbox'命令,這是行不通的。我猜測我將不得不一一瀏覽所有參數。有什麼建議嗎? – BRogers 2013-06-14 00:50:01
你是什麼意思「不起作用?」你可以說得更詳細點嗎? – x0n 2013-06-14 14:53:04
我正在使用帶有參數('New-Mailbox')的命令,而且我正在接近與他相同的錯誤(只是使用'New-Mailbox'而不是他正在運行的命令)。我使用'pipeline.Commands.AddScript(腳本)',我仍然得到這個錯誤。我想我必須使用'var cmd = new Command(script,true);'use'cmd.Parameters.Add(「key」,「value」);' - 對此有任何建議。我還沒有解決,但那將是我的下一次嘗試。 – BRogers 2013-06-14 16:11:19