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

Kerwin Rean Kallego 41 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

Active Directory
Active Directory
A set of directory-based technologies included in Windows Server.
5,542 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,273 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Ian Xue (Shanghai Wicresoft Co., Ltd.) 27,431 Reputation points Microsoft Vendor
    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