Salut !

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
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
#Generated Form Function
import-module activedirectory
function GenerateForm {
########################################################################
# Code Generated By: SAPIEN Technologies PrimalForms (Community Edition) v1.0.10.0
# Generated On: 05/09/2015 13:48
# Generated By: 
########################################################################

#region Import the Assemblies
[reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null
[reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null
#endregion

#region Generated Form Objects
$form1 = New-Object System.Windows.Forms.Form
$Label_ville = New-Object System.Windows.Forms.Label
$comboBox2_ville = New-Object System.Windows.Forms.ComboBox
$comboBox1_BU = New-Object System.Windows.Forms.ComboBox
$Label_BU = New-Object System.Windows.Forms.Label
$textBox_prenom = New-Object System.Windows.Forms.TextBox
$Label_Prenom = New-Object System.Windows.Forms.Label
$textBox_name = New-Object System.Windows.Forms.TextBox
$Label_Nom = New-Object System.Windows.Forms.Label
$InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState
#endregion Generated Form Objects

#----------------------------------------------
#Generated Event Script Blocks
#----------------------------------------------
#Provide Custom Code for events specified in PrimalForms.
$Combobox1_BU_SelectedIndexChanged={
Load-ComboBox $Combobox2_Ville (Get-ADOrganizationalUnit -searchbase "OU=$UO,DC=CONTOSO,DC=FR" -Searchscope 1 -Filter * ) -DisplayMember "Name"
}
$handler_label4_Click= 
{
#TODO: Place custom script here

}

$handler_label2_Click= 
{
#TODO: Place custom script here

}

$handler_comboBox1_SelectedIndexChanged= 
{
#TODO: Place custom script here

}

$handler_label1_Click= 
{
#TODO: Place custom script here

}

$handler_form1_Load= 
{
#TODO: Place custom script here

}

$OnLoadForm_StateCorrection=
{#Correct the initial state of the form to prevent the .Net maximized form issue
	$form1.WindowState = $InitialFormWindowState
}

#----------------------------------------------
#region Generated Form Code
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 207
$System_Drawing_Size.Width = 387
$form1.ClientSize = $System_Drawing_Size
$form1.DataBindings.DefaultDataSourceUpdateMode = 0
$form1.Name = "form1"
$form1.Text = "Primal Form"
$form1.add_Load($handler_form1_Load)
function Load-ComboBox 
{
    Param (
        [Parameter(Mandatory=$true)]
        [System.Windows.Forms.ComboBox]$ComboBox,
        [Parameter(Mandatory=$true)]
        $Items,
        [Parameter(Mandatory=$false)]
        [string]$DisplayMember,
        [switch]$Append
    )
    
    if(-not $Append)
    {
        $comboBox.Items.Clear()    
    }
    
    if($Items -is [Array])
    {
        $comboBox.Items.AddRange($Items)
    }
    else
    {
        $comboBox.Items.Add($Items)    
    }

    $comboBox.DisplayMember = $DisplayMember    
}

$Label_ville.DataBindings.DefaultDataSourceUpdateMode = 0

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 12
$System_Drawing_Point.Y = 109
$Label_ville.Location = $System_Drawing_Point
$Label_ville.Name = "Label_ville"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 23
$System_Drawing_Size.Width = 55
$Label_ville.Size = $System_Drawing_Size
$Label_ville.TabIndex = 7
$Label_ville.Text = "Ville"
$Label_ville.add_Click($handler_label4_Click)

$form1.Controls.Add($Label_ville)

$comboBox2_ville.DataBindings.DefaultDataSourceUpdateMode = 0
$comboBox2_ville.DropDownStyle = 2
$comboBox2_ville.FormattingEnabled = $True
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 73
$System_Drawing_Point.Y = 109
$comboBox2_ville.Location = $System_Drawing_Point
$comboBox2_ville.Name = "comboBox2_ville"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 21
$System_Drawing_Size.Width = 134
$comboBox2_ville.Size = $System_Drawing_Size
$comboBox2_ville.TabIndex = 6
Load-ComboBox $Combobox2_Ville (Get-ADOrganizationalUnit -searchbase "OU=$UO,DC=CONTOSO,DC=FR" -Searchscope 1 -Filter * ) -DisplayMember "Name"
$comboBox1_BU.add_SelectedIndexChanged($comboBox1_BU_SelectedIndexChanged)

$form1.Controls.Add($comboBox2_ville)

$comboBox1_BU.DataBindings.DefaultDataSourceUpdateMode = 0
$comboBox1_BU.DropDownStyle = 2
$comboBox1_BU.FormattingEnabled = $True
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 73
$System_Drawing_Point.Y = 80
$comboBox1_BU.Location = $System_Drawing_Point
$comboBox1_BU.Name = "comboBox1_BU"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 21
$System_Drawing_Size.Width = 134
$comboBox1_BU.Size = $System_Drawing_Size
$comboBox1_BU.TabIndex = 5
Load-ComboBox $Combobox1_BU (Get-ADOrganizationalUnit -Searchscope 1 -Filter * ) -DisplayMember "Name"
$Combobox1_BU.SelectedItem = $comboBox1_BU.Items[0]
$UO = $Combobox1_BU.SelectedItem

$form1.Controls.Add($comboBox1_BU)

$Label_BU.DataBindings.DefaultDataSourceUpdateMode = 0

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 13
$System_Drawing_Point.Y = 83
$Label_BU.Location = $System_Drawing_Point
$Label_BU.Name = "Label_BU"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 23
$System_Drawing_Size.Width = 64
$Label_BU.Size = $System_Drawing_Size
$Label_BU.TabIndex = 4
$Label_BU.Text = "BU "

$form1.Controls.Add($Label_BU)

$textBox_prenom.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 73
$System_Drawing_Point.Y = 53
$textBox_prenom.Location = $System_Drawing_Point
$textBox_prenom.Name = "textBox_prenom"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 20
$System_Drawing_Size.Width = 134
$textBox_prenom.Size = $System_Drawing_Size
$textBox_prenom.TabIndex = 3

$form1.Controls.Add($textBox_prenom)

$Label_Prenom.DataBindings.DefaultDataSourceUpdateMode = 0

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 13
$System_Drawing_Point.Y = 60
$Label_Prenom.Location = $System_Drawing_Point
$Label_Prenom.Name = "Label_Prenom"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 23
$System_Drawing_Size.Width = 64
$Label_Prenom.Size = $System_Drawing_Size
$Label_Prenom.TabIndex = 2
$Label_Prenom.Text = "Prenom "
$Label_Prenom.add_Click($handler_label2_Click)

$form1.Controls.Add($Label_Prenom)

$textBox_name.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 73
$System_Drawing_Point.Y = 24
$textBox_name.Location = $System_Drawing_Point
$textBox_name.Name = "textBox_name"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 20
$System_Drawing_Size.Width = 134
$textBox_name.Size = $System_Drawing_Size
$textBox_name.TabIndex = 1

$form1.Controls.Add($textBox_name)

$Label_Nom.DataBindings.DefaultDataSourceUpdateMode = 0

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 13
$System_Drawing_Point.Y = 27
$Label_Nom.Location = $System_Drawing_Point
$Label_Nom.Name = "Label_Nom"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 23
$System_Drawing_Size.Width = 82
$Label_Nom.Size = $System_Drawing_Size
$Label_Nom.TabIndex = 0
$Label_Nom.Text = "Nom"
$Label_Nom.add_Click($handler_label1_Click)

$form1.Controls.Add($Label_Nom)

#endregion Generated Form Code

#Save the initial state of the form
$InitialFormWindowState = $form1.WindowState
#Init the OnLoad event to correct the initial state of the form
$form1.add_Load($OnLoadForm_StateCorrection)
#Show the Form
$form1.ShowDialog()| Out-Null

} #End Function

#Call the Function
GenerateForm

En résumé :

La combobox1 récupère mes OU de premier niveau

La deuxième est censé me récupérer les OU qu'il y a a l'interieur de la première

Problème : Je ne sais pas comment on récupère l'OU sélectionné dans la premiere combobox

Quand j'essaye :

Pour recuperer la valeur de la 1ère combobox :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
$UO = $Combobox1_BU.SelectedItem
---
Load-ComboBox $Combobox2_Ville (Get-ADOrganizationalUnit -searchbase "OU=$UO,DC=CONTOSO,DC=FR" -Searchscope 1 -Filter * ) -DisplayMember "Name"
J'ai une erreur

La syntaxe de l'objet est incorrecte

Merci pour votre aide