troubleshooting Question

Getting output of invoke command into a combo box

Avatar of DevSupport
DevSupport asked on
Powershell
1 Comment1 Solution93 ViewsLast Modified:
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
Join our community to see this answer!
Unlock 1 Answer and 1 Comment.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 1 Comment.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros