Answer the question
In order to leave comments, you need to log in
combo box. ValueMember and DisplayMember properties in powershell?
There is a code sketch, a simple display of containers from AD:
cls
[array]$test = Get-ADOrganizationalUnit -filter * -SearchBase "dc=DOMAIN,dc=local"
Function funMainForm {
$Global:main_form = New-Object System.Windows.Forms.Form
$main_form.Text ='Окно'
$main_form.Width = 600
$main_form.Height = 480
$main_form.AutoSize = $true
$Global:cmbTest = New-Object System.Windows.Forms.ComboBox
$cmbTest.Width = 620
$cmbTest.DisplayMember = "name"
$cmbTest.ValueMember = "DistinguishedName"
$cmbTest.DataSource = $test
$cmbTest.Location = New-Object System.Drawing.Point(10,50)
$main_form.Controls.Add($cmbTest)
$main_form.ShowDialog()
}
funMainForm
Answer the question
In order to leave comments, you need to log in
In general, I understand what the problem is. ValueMember and DisplayMember work if $cmbTest.DataSource is set to data of type DataTable and standard output in powershell is of type Array. Because there are no built-in ways to convert an Array to a DataTable, I used the following function:
https://gallery.technet.microsoft.com/scriptcenter...
Accordingly, I changed the first line in my code to:
[System.Data.datatable]$test = Get-ADOrganizationalUnit -filter * -SearchBase "dc=DOMAIN,dc=local" | Out-DataTable
Not too familiar with PowerShell, but in general terms DisplayMember is a property that is output to the combobox instead of ToString(). ValueMember is the name of the property, which can be quickly obtained through the combobox without any additional steps. For example, SelectedValue will immediately return the ValueMember of the selected object.
There is a suspicion that property names are case sensitive. Try Name and distinguishedName
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question