Script C# lance un Script Powershell et mauvais retour.
Bonjour à tous,
j'ai un script C# permettant de lancer une commande PowerShell et récupérer le résultat dans une variables string.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| string FonctionScriptPowerShellDansString(string MonScript)
{
string Retour;
using (Process process = new Process())
{
process.StartInfo.FileName = "powershell.exe";
process.StartInfo.Arguments = "-NoProfile -ExecutionPolicy Bypass -Command " + "\"" + MonScript + "\"";
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.UseShellExecute = false;
process.StartInfo.CreateNoWindow = true;
process.Start();
Retour = process.StandardOutput.ReadLine(); // ou ReadToEnd si on veux le fichier complet
process.WaitForExit();
}
return Retour;
} |
Ce code fonctionne bien, mais quand le résultat Powershell comporte un caractère spécial ça ne remonte pas le bon texte
ex: "Réseau" ==> "R,seau".
Une idée de comment corriger ce problème ?