How do I get the data and add it to my listbox item choices?

Kerwin Rean Kallego 61 Reputation points
2023-07-23T01:42:57.29+00:00

$OuListBox = New-Object System.Windows.Forms.ListBox

$OuListBox.Location = New-Object System.Drawing.Point(10,50)

$OuListBox.Height = 200

$OuListBox.Width = 150

$OuListBox.HorizontalScrollbar = $True

$OuListBox.Items.Add($OUName) #it should list the items in my listbox

$Appform.Controls.Add($OuListBox)

User's image

Active Directory
Active Directory
A set of directory-based technologies included in Windows Server.
6,856 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,620 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,793 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Kerwin Rean Kallego 61 Reputation points
    2023-07-23T02:07:08.29+00:00

    Nevermind, found the solution to my question by adding foreach in my pipeline.

    Get-ADOrganizationalUnit -LDAPFilter '(name=*)' -SearchBase 'OU=OUname,DC=DCname,DC=DClocal' -SearchScope OneLevel | foreach{[void]$OuListBox.Items.Add($_.name)}

    0 comments No comments

Your answer

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