Getting output of invoke command into a combo box

Hi Experts,

I am trying to get a servername from a text box and list its tomcat services as combo box items by putting it into array and displaying as dropdown.

I have created a button to fetch the items.

I can see that the invoke command works but does not populate into the Combo box.

$objappsvrname = New-Object System.Windows.Forms.TextBox
$objappsvrname.Location = New-Object System.Drawing.Size(20,45)
$objappsvrname.Size = New-Object System.Drawing.Size(260,15)
    $objForm.Controls.Add($objappsvrname)

$objloadbutton = New-Object System.Windows.Forms.Button
      $objloadbutton.Location = New-Object System.Drawing.Size(290,70)
      $objloadbutton.Size = New-Object System.Drawing.Size(75,20)
      $objloadbutton.Text = "Show TC"
      $objloadbutton.Add_Click({PopulateDBList2})
$objForm.Controls.Add($objloadbutton)




function PopulateDBList2{
$objAppDropDown = New-Object System.Windows.Forms.ComboBox
$objAppDropDown.Location = New-Object System.Drawing.Size(20,70)
$objAppDropDown.Size = New-Object System.Drawing.Size(260,15)
$servn = $objappsvrname.Text
write-host $servn
$ServiceNameArr = @()
$ServiceNameArr = (Invoke-Command -Computername $servn -ScriptBlock { Get-WMIObject Win32_Service -Filter "DisplayName LIKE '%Apache%'" | Select -ExpandProperty DisplayName })

ForEach ($item in $ServiceNameArr){
    $objAppDropDown.items.add($item.Name)
    write-host $item.Name
}
$objForm.Controls.Add($objAppDropDown)
}

Request you to please let me know what I am missing.
DevSupportAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

oBdACommented:
The "item.Name" is incorrect. You're already expanding the DisplayName property, so you have a simple array of strings, and need to use the loop variable as it is.
ForEach ($item in $ServiceNameArr){
	$objAppDropDown.items.add($item)
	write-host $item
}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.