Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

AD Groups in Listbox

$
0
0

I am trying to output AD security Groups into a listbox using the code below:

$objListboxADGroups = New-Object System.Windows.Forms.Listbox
$objListboxADGroups.Location = New-Object System.Drawing.Size(100,200)
$objListboxADGroups.Size = New-Object System.Drawing.Size(260,20)

 $objListboxADGroups.SelectionMode = "MultiExtended"

 $ADSecurityGroup = get-adgroup -filter {groupcategory -eq "security"} -SearchBase "ou=someOU,ou=someotherOU,dc=domain,dc=com"
foreach ($SecurityGroup in $ADSecurityGroup)
{

[void] $objListboxADGroups.Items.Add($securitygroup)
}

$objListboxADGroups.Height = 70
$objForm.Controls.Add($objListboxADGroups)

 

That works along with the rest of the code (omitted). The problem is that it displays in the form the full DN. I can add "select name" or "select-object name" which will show the name only in the variable, but in the listbox on the form it displays as "@{name=nameofsecuritygroup}

How can I make the listbox on the form display only the name of the security group?


Viewing all articles
Browse latest Browse all 6937

Trending Articles