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.TextB ox
$objappsvrname.Location = New-Object System.Drawing.Size(20,45)
$objappsvrname.Size = New-Object System.Drawing.Size(260,15 )
$objForm.Controls.Add($obj appsvrname )
$objloadbutton = New-Object System.Windows.Forms.Butto n
$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({ PopulateDB List2})
$objForm.Controls.Add($obj loadbutton )
function PopulateDBList2{
$objAppDropDown = New-Object System.Windows.Forms.Combo Box
$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($obj AppDropDow n)
}
Request you to please let me know what I am missing.
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.TextB
$objappsvrname.Location = New-Object System.Drawing.Size(20,45)
$objappsvrname.Size = New-Object System.Drawing.Size(260,15
$objForm.Controls.Add($obj
$objloadbutton = New-Object System.Windows.Forms.Butto
$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({
$objForm.Controls.Add($obj
function PopulateDBList2{
$objAppDropDown = New-Object System.Windows.Forms.Combo
$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(
write-host $item.Name
}
$objForm.Controls.Add($obj
}
Request you to please let me know what I am missing.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.