0

I am writing a script with a GUI for work and I have an Issue that I am having trouble getting past. I am trying to get the Department to show all of our departments in a combobox but when the script pulls the departments from the AD it also displays the @{Name= before every department name (see image below).

Here is the block I am having issues with

$DepGroups = Get-ADGroup -Filter * -SearchBase "OU=Our Departments,DC=ourDC,DC=com" |
             select Name | Sort -Property Name
$DepBox = New-Object System.Windows.Forms.ComboBox
$DepBox.Width = 136
$DepBox.Height = 20
$DepBox.Location = New-Object System.Drawing.Point(95,53)
$DepBox.Font = "Microsoft Sans Serif,10"
$DepBox.DropDownStyle = 'DropDownList'
$DepBox.Items.AddRange($DepGroups)
$Form.Controls.Add($DepBox)

Image

1

1 Answer 1

0

Uusing the | Select pipe will return an object with the selected attributes in it, in this case just the Name.

You should use ( < obj > ).Name to just get the value of the Name attribute.

i.e.

$DepGroups = (Get-ADGroup -Filter * -SearchBase "OU=Our Departments,DC=ourDC,DC=com").Name | <Any additional sorting>
Sign up to request clarification or add additional context in comments.

1 Comment

Yes this is exactly what I needed Thank you very much!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.