retrieve the value of a combobox (AD)
hello !
i have active directory :
-a
--a1
--a2
---a2.1
...
i made gui primal forms :
#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: jeremy ######################################################################## #region import 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 events specified in primalforms. $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 initial state of form prevent .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=$ou,dc=sodiaal,dc=fr" -searchscope 1 -filter * ) -displaymember "name" $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 $combobox1_bu.add_selectedindexchanged($handler_combobox1_selectedindexchanged) load-combobox $combobox1_bu (get-adorganizationalunit -searchbase "dc=sodiaal,dc=fr" -searchscope 1 -filter * ) -displaymember "name" $combobox1_bu.selecteditem = $combobox1_bu.items[0] $ou = $combobox1_bu.items[0] $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 initial state of form $initialformwindowstate = $form1.windowstate #init onload event correct initial state of form $form1.add_load($onloadform_statecorrection) #show form $form1.showdialog()| out-null } #end function #call function generateform
error :
get-adorganizationalunit : syntax of object name incorrect
combobox2_ville (get-adorganizationalunit <<<< -searchbase "ou=$ou, dc=contoso,dc=fr" - searchscope 1 -filter * ) -displaymember "name"
i can not seem have value of second combobox
if put value manually works
can me ?
thank :)
my last offer. here complete , working demo of how use comboboxes.
#---------------------------------------------- # generated form function #---------------------------------------------- function call-demo-comborelation_pff { #---------------------------------------------- #region import assemblies #---------------------------------------------- [void][reflection.assembly]::load('system.windows.forms, version=2.0.0.0, culture=neutral, publickeytoken=b77a5c561934e089') #endregion import assemblies #---------------------------------------------- #region generated form objects #---------------------------------------------- [system.windows.forms.application]::enablevisualstyles() $formcombodemowmibrowser = new-object 'system.windows.forms.form' $combobox3 = new-object 'system.windows.forms.combobox' $textbox1 = new-object 'system.windows.forms.textbox' $combobox2 = new-object 'system.windows.forms.combobox' $combobox1 = new-object 'system.windows.forms.combobox' $buttonok = new-object 'system.windows.forms.button' $initialformwindowstate = new-object 'system.windows.forms.formwindowstate' #endregion generated form objects #---------------------------------------------- # user generated script #---------------------------------------------- $formevent_load = { $p = get-wmiobject -list win32_* | sort name load-combobox $combobox3 -items $p -displaymember name } #region control helper functions function load-combobox { <# .synopsis this functions helps load items combobox. .description use function dynamically load items combobox control. .parameter combobox the combobox control want add items to. .parameter items the object or objects wish load combobox's items collection. .parameter displaymember indicates property display items in control. .parameter append adds item(s) combobox without clearing items collection. .example load-combobox $combobox1 "red", "white", "blue" .example load-combobox $combobox1 "red" -append load-combobox $combobox1 "white" -append load-combobox $combobox1 "blue" -append .example load-combobox $combobox1 (get-process) "processname" #> param ( [validatenotnull()] [parameter(mandatory = $true)] [system.windows.forms.combobox]$combobox, [validatenotnull()] [parameter(mandatory = $true)] $items, [parameter(mandatory = $false)] [string]$displaymember, [switch]$append ) if (-not $append) { $combobox.items.clear() } if ($items -is [object[]]) { $combobox.items.addrange($items) } elseif ($items -is [array]) { $combobox.beginupdate() foreach ($obj in $items) { $combobox.items.add($obj) } $combobox.endupdate() } else { $combobox.items.add($items) } $combobox.displaymember = $displaymember } #endregion $combobox1_selectedindexchanged = { $items = ($combobox1.selecteditem).getrelated() | select __class load-combobox $combobox2 -items $items -displaymember '__class' } $combobox2_selectedindexchanged = { $textbox1.text = $combobox1.selecteditem.getrelated($combobox2.selecteditem.'__class') | format-list | out-string } $combobox3_selectedindexchanged = { $p = get-wmiobject "$($combobox3.selecteditem.name)" load-combobox $combobox1 -items $p -displaymember caption } # --end user generated script-- #---------------------------------------------- #region generated events #---------------------------------------------- $form_statecorrection_load = { #correct initial state of form prevent .net maximized form issue $formcombodemowmibrowser.windowstate = $initialformwindowstate } $form_cleanup_formclosed = { #remove event handlers controls try { $combobox3.remove_selectedindexchanged($combobox3_selectedindexchanged) $combobox2.remove_selectedindexchanged($combobox2_selectedindexchanged) $combobox1.remove_selectedindexchanged($combobox1_selectedindexchanged) $formcombodemowmibrowser.remove_load($formevent_load) $formcombodemowmibrowser.remove_load($form_statecorrection_load) $formcombodemowmibrowser.remove_formclosed($form_cleanup_formclosed) } catch [exception] { } } #endregion generated events #---------------------------------------------- #region generated form code #---------------------------------------------- $formcombodemowmibrowser.suspendlayout() # # formcombodemowmibrowser # $formcombodemowmibrowser.controls.add($combobox3) $formcombodemowmibrowser.controls.add($textbox1) $formcombodemowmibrowser.controls.add($combobox2) $formcombodemowmibrowser.controls.add($combobox1) $formcombodemowmibrowser.controls.add($buttonok) $formcombodemowmibrowser.acceptbutton = $buttonok $formcombodemowmibrowser.clientsize = '795, 503' $formcombodemowmibrowser.formborderstyle = 'fixeddialog' $formcombodemowmibrowser.maximizebox = $false $formcombodemowmibrowser.minimizebox = $false $formcombodemowmibrowser.name = "formcombodemowmibrowser" $formcombodemowmibrowser.startposition = 'centerscreen' $formcombodemowmibrowser.text = "combo demo wmi browser" $formcombodemowmibrowser.add_load($formevent_load) # # combobox3 # $combobox3.formattingenabled = $true $combobox3.location = '36, 13' $combobox3.name = "combobox3" $combobox3.size = '435, 21' $combobox3.tabindex = 4 $combobox3.text = "win32_printer" $combobox3.add_selectedindexchanged($combobox3_selectedindexchanged) # # textbox1 # $textbox1.location = '36, 75' $textbox1.multiline = $true $textbox1.name = "textbox1" $textbox1.scrollbars = 'both' $textbox1.size = '638, 403' $textbox1.tabindex = 3 # # combobox2 # $combobox2.formattingenabled = $true $combobox2.location = '368, 48' $combobox2.name = "combobox2" $combobox2.size = '306, 21' $combobox2.tabindex = 2 $combobox2.add_selectedindexchanged($combobox2_selectedindexchanged) # # combobox1 # $combobox1.formattingenabled = $true $combobox1.location = '36, 48' $combobox1.name = "combobox1" $combobox1.size = '298, 21' $combobox1.tabindex = 1 $combobox1.add_selectedindexchanged($combobox1_selectedindexchanged) # # buttonok # $buttonok.anchor = 'bottom, right' $buttonok.dialogresult = 'ok' $buttonok.location = '697, 75' $buttonok.name = "buttonok" $buttonok.size = '75, 23' $buttonok.tabindex = 0 $buttonok.text = "ok" $buttonok.usevisualstylebackcolor = $true $formcombodemowmibrowser.resumelayout() #endregion generated form code #---------------------------------------------- #save initial state of form $initialformwindowstate = $formcombodemowmibrowser.windowstate #init onload event correct initial state of form $formcombodemowmibrowser.add_load($form_statecorrection_load) #clean control events $formcombodemowmibrowser.add_formclosed($form_cleanup_formclosed) #show form return $formcombodemowmibrowser.showdialog() } #end function call-demo-comborelation_pff
\_(ツ)_/
Windows Server > Windows PowerShell
Comments
Post a Comment