Bonjour à tous,

J'a récupéré un morceau de script graphique que j'ai modifié et qui doit en fonction du choix exécuter un ensemble de code (lire un fichier, changer une ligne d'adresse IP puis le sauvegarder).
Mais malheureusement, le résultat est toujours le même.
Le script envoi sur le premier choix malgré les divers choix sélectionnés, impossible de renvoyer sur les autres choix.

J'ai eu beau chercher un peu partout, je ne trouve aucune réponse sur cela.

Si vous pouviez me dire qu'est ce qui cloche se serait TOP !!

Merci d'avance et bonne journée.

Code PowerShell : 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
Add-Type -assembly System.Windows.Forms 
 
<#01#>
$Form = New-Object System.Windows.Forms.Form
$Form.Text = "APP WIN x64"
$Form.Width = 340
$Form.Height = 220
$Form.StartPosition = [System.Windows.Forms.FormStartPosition]::CenterScreen
 
<#Icon#>
$objIcon = New-Object system.drawing.icon ("C:\APP.ICO")
$Form.Icon = $objIcon
 
<#02#>
$Label1 = New-Object System.Windows.Forms.Label
$Label1.Location = New-Object System.Drawing.Point(90,05)
$Label1.Size = New-Object System.Drawing.Size(150,15)
$Label1.Text = '--- SYSTEM ---'
$Label1.Font = New-Object System.Drawing.Font("Arial",10,[System.Drawing.FontStyle]::Bold)
$Form.Controls.Add($Label1)
 
<#Date#>
$Label2 = New-Object System.Windows.Forms.Label
$Label2.Location = New-Object System.Drawing.point(260,11) 
$Label2.Size = New-Object System.Drawing.Size(280,15) 
$Label2.Text = Get-Date -UFormat "%d-%m-%Y"
$Label2.Font = New-Object System.Drawing.Font("Arial",07,[System.Drawing.FontStyle]::Regular)
$Form.Controls.Add($Label2) 
 
<#Time#>
$Label3 = New-Object System.Windows.Forms.Label
$Label3.Location = New-Object System.Drawing.point(284,24) 
$Label3.Size = New-Object System.Drawing.Size(280,15) 
$Label3.Text = Get-Date -UFormat "%R"
$Label3.Font = New-Object System.Drawing.Font("Arial",07,[System.Drawing.FontStyle]::Regular)
$Form.Controls.Add($Label3)
 
<#03#>
$Label4 = New-Object System.Windows.Forms.Label
$Label4.Location = New-Object System.Drawing.Point(10,30)
$Label4.Size = New-Object System.Drawing.Size(280,15)
$Label4.Text = 'Sélecte APP :'
$Label4.Font = New-Object System.Drawing.Font("Arial",08,[System.Drawing.FontStyle]::Regular)
$Form.Controls.Add($Label4)
 
<#04 L300xH90#>
$ListBox = New-Object System.Windows.Forms.ListBox 
$ListBox.Location = New-Object System.Drawing.Point(10,45) 
$ListBox.Size = New-Object System.Drawing.Size(300,90) 
$ListBox.Height = 90
 
<#05#>
[void] $ListBox.Items.Add("ACTION 01")
[void] $ListBox.Items.Add("ACTION 02")
[void] $ListBox.Items.Add("ACTION 03")
[void] $ListBox.Items.Add("ACTION 04")
[void] $ListBox.Items.Add("ACTION 05")
[void] $ListBox.Items.Add("ACTION 06")
 
<#OKbutton#>
$OKButton = New-Object System.Windows.Forms.Button
$OKButton.Location = New-Object System.Drawing.Size(75,135)
$OKButton.Size = New-Object System.Drawing.Size(75,23)
$OKButton.Text = "OK"
$OKButton.Add_Click({$CSP=$ListBox.SelectedItem;$Form.Close()})
$Form.Controls.Add($OKButton)
 
<#OKButon action Valide#>
$Form.KeyPreview = $True
$Form.Add_KeyDown({if ($_.KeyCode -eq "Enter") 
{$CSP=$ListBox.SelectedItem;$Form.Close()}})
 
<#Button Cancel#>
$CancelButton = New-Object System.Windows.Forms.Button
$CancelButton.Location = New-Object System.Drawing.Point(170,135)
$CancelButton.Size = New-Object System.Drawing.Size(75,23)
$CancelButton.Text = 'Cancel'
$CancelButton.DialogResult = [System.Windows.Forms.DialogResult]::Cancel
$Form.CancelButton = $CancelButton
$Form.Controls.Add($CancelButton)
 
<#Text#>
$Label5 = New-Object System.Windows.Forms.Label
$Label5.Location = New-Object System.Drawing.point(10,164) 
$Label5.Size = New-Object System.Drawing.Size(60,15) 
$Label5.Text = "Sign"
$Label5.Font = New-Object System.Drawing.Font("Arial",08,[System.Drawing.FontStyle]::Regular)
$Form.Controls.Add($Label5) 
 
<#Text Adresse Sign#>
$Label6 = New-Object System.Windows.Forms.Label
$Label6.Location = New-Object System.Drawing.point(110,167) 
$Label6.Size = New-Object System.Drawing.Size(260,15) 
$Label6.Text = "000.000.00"
$Label6.Font = New-Object System.Drawing.Font("Arial",06,[System.Drawing.FontStyle]::Regular)
$Form.Controls.Add($Label6) 
 
$Form.Controls.Add($ListBox) 
$Form.Topmost = $True
$Form.Add_Shown({$Form.Activate()})
$Form.ShowDialog()
 
<#Résultat#>
If ($CSP = "ACTION 01")  
{
'ACTION 01'
(Get-Content -Path "C:\File.txt") |
ForEach-Object {$_ -replace "Host.+", ("Host =" + " 192.168.0.30)")} |
Set-Content -Path ("C:\File.txt") -Force;
}
 
ElseIf ($CSP = "ACTION 02")  
{
'ACTION 02'
(Get-Content  -Path "C:\File.txt") |
Foreach-Object {$_ -replace "Host.+", ("Host =" + " 192.168.0.31)")} |
Set-Content -Path ("C:\File.txt") -Force;
}
 
ElseIf ($CSP = "ACTION 03")  
{
'ACTION 03'
(Get-Content  -Path "C:\File.txt") |
Foreach-Object {$_ -replace "Host.+", ("Host =" + " 192.168.0.32)")} |
Set-Content -Path ("C:\File.txt") -Force;
}
 
ElseIf ($CSP = "ACTION 04")  
{
'ACTION 04'
(Get-Content  -Path "C:\File.txt") |
Foreach-Object {$_ -replace "Host.+", ("Host =" + " 192.168.0.33)")} |
Set-Content -Path ("C:\File.txt") -Force;
}
 
ElseIf ($CSP = "ACTION 05")  
{
'ACTION 05'
(Get-Content  -Path "C:\File.txt") |
Foreach-Object {$_ -replace "Host.+", ("Host =" + " 192.168.0.34)")} |
Set-Content -Path ("C:\File.txt") -Force;
}
 
ElseIf ($CSP = "ACTION 06")  
{
'ACTION 06'
(Get-Content  -Path "C:\File.txt") |
Foreach-Object {$_ -replace "Host.+", ("Host =" + " 192.168.0.35)")} |
Set-Content -Path ("C:\File.txt") -Force
}