Salut à tous,
Sur une machine Virtuelle VMWare, je dois créer une DLL permettant de lancer un script PowerCLI.
Pour faire des essais, je souahite faire un programme simple composé de 3 éléments :
- Un textbox pour y entrer le script a lancer
- un bouton pour lancer ce script
- un textbox pour afficher le resultat du script.

J'ai fait cela pour un script PowerShell est ça fonctionne.
Mon code :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Management.Automation;
using System.IO;
 
namespace TestVMWare
{
    /// <summary>
    /// Logique d'interaction pour MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }
 
        public string LanceScriptPowerShell(string monScript)
        {
            string FichierTemp = "C:\\Windows\\Temp\\RetourPowerShell.txt";
            string ScriptEntier = monScript + " > " + FichierTemp;
            string MonRetourPowerShell;
            try
            {
                //using System.Management.Automation; pour utiliser les Script PowerShell
                // Et ajouter la DLL depuis C:\Program Files (x86)\Reference Assemblies\Microsoft\WindowsPowerShell\3.0
                PowerShell powerShell = PowerShell.Create();
                powerShell.AddScript(ScriptEntier);
                powerShell.Invoke();
            }
            catch (Exception ex)
            {
                MonRetourPowerShell = "Le Script n'est pas fonctionnel : " + ex;
                return MonRetourPowerShell;
            }
            //using System.IO; pour Utiliser StreamReader
            if (File.Exists(FichierTemp))
            {
                StreamReader FichierALire = new StreamReader(FichierTemp);
                MonRetourPowerShell = FichierALire.ReadToEnd();
                FichierALire.Close();
                File.Delete(FichierTemp);
            }
            else
            {
                MonRetourPowerShell = "Le Script n'est pas fonctionnel";
            }
            return MonRetourPowerShell;
        }
 
        private void BoutonTest1_Click(object sender, RoutedEventArgs e)
        {
            string monScript, monResultat;
            monScript = TxtBoxScipt.Text;
            monResultat = LanceScriptPowerShell(monScript);
            TxtBoxResultat.Text = monResultat;
        }
    }
}
Maintenant, je voudrait faire la même chose pour un script PowerCLI.
Je ne connait pas vraiment la différence entre PowerShell et PowerCLI.
Pouvez-vous m'aider ?
Je ne dispose malheureusement pas des machines pour essayer.
J'ai trouvé pas mal de chose sur le net, mais rien de vraiment concret.
Merci