0
Comment puis-je obtenir le code de retour de la commande suivante:Exchange Management Powershell avec .Net Retour code
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();
Pourquoi retournerait-il toujours vrai, même s'il ne créait pas le groupe de récupération tel qu'il existait déjà? – RPS
L'état d'exécution est un peu étrange dans PowerShell, IIRC indique qu'une erreur de terminaison est survenue par exemple. 'gci xyzzy; $? 'renvoie True même si le fichier n'existe pas. Vous pouvez capturer des erreurs sans fin de plusieurs façons, mais le plus simple est d'utiliser le paramètre omniprésent -ErrorVariable (-ev pour faire court). '$ status = $ null; gci xyzzy -ev statut; $ status' - dans ce cas, $ status contiendra les informations d'erreur sans fin. –