We help IT Professionals succeed at work.

Getting output of invoke command into a combo box

DevSupport
DevSupport asked
on
86 Views
Last Modified: 2017-03-17
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.
Comment
Watch Question

CERTIFIED EXPERT
Most Valuable Expert 2019
Most Valuable Expert 2018
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions