Link to home
Start Free TrialLog in
Avatar of DevSupport
DevSupport

asked on

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.
ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial