具有.Net返回码的Exchange管理Powershell

时间:2010-07-19 20:41:48

标签: .net powershell

如何从以下命令获取返回码:

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";

    //Add the command to the Commands collection of the pipeline.
    pipeline.Commands.AddScript(strScript)

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

1 个答案:

答案 0 :(得分:0)

您可以通过获取$的值来查询最后一个命令(布尔值)的执行状态。变量,例如:

bool succeeded = myRunspace.SessionStateProxy.GetVariable("?");