How do I fetch the DATA and add it to my listbox item choices?

Kerwin Rean Kallego 61 Reputation points
2023-07-23T01:40:02.7766667+00:00

$ListBox = New-Object System.Windows.Forms.ListBox $ListBox.Location = New-Object System.Drawing.Point(10,50) $ListBox.Height = 200 $ListBox.Width = 150 $ListBox.HorizontalScrollbar = $True $ListBox.Items.Add($OUName) #The List of OU should be listed as my choices in my listbox items. $Appform.Controls.Add($ListBox)

enter image description here

Windows for business | Windows Client for IT Pros | Directory services | Active Directory
Windows for business | Windows Server | User experience | PowerShell
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Anonymous
    2023-07-24T05:34:27.23+00:00

    Hi,

    You can get the OU names from the Name property and add the array to the listbox using AddRange().

    $ListBox = New-Object System.Windows.Forms.ListBox
    $ListBox.Location = New-Object System.Drawing.Point(10,50)
    $ListBox.Height = 200 
    $ListBox.Width = 150 
    $ListBox.HorizontalScrollbar = $True 
    $OUName=(Get-ADOrganizationalUnit -LDAPFilter '(name=*)' -SearchBase '...' -SearchScope OneLevel).name 
    $Listbox.Items.AddRange($OUName) 
    #The List of OU should be listed as my choices in my listbox items. 
    $Appform.Controls.Add($ListBox)
    

    Best Regards,

    Ian Xue


    If the Answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.