Output Box not displaying

Evening all

Any reason why the below will not display in the outputbox? It’s just blank with no errors

 function graphics {

$HostName=$InputBox.text;
 
$card = get-wmiobject Win32_VideoController -ComputerName $HostName
$graphics = $card.caption
$outputBoxGcard.text=$graphics }

$outputBoxGcard = New-Object System.Windows.Forms.TextBox
$outputBoxGcard.Font = "Bartclays,8"
$outputBoxGcard.Location = New-Object System.Drawing.Size(10,210)
$outputBoxGcard.Size = New-Object System.Drawing.Size(150,60)
$outputBoxGcard.TextAlign = "Center"
$outputBoxGcard.MultiLine = $True
$HardWare.Controls.Add($outputBoxGcard)


$ButtonMon = New-Object System.Windows.Forms.Button
$ButtonMon.Location = New-Object System.Drawing.Size(385,180)
$ButtonMon.Size = New-Object System.Drawing.Size(50,30)
$ButtonMon.Text = "Monitor Sizes"
$ButtonMon.Add_Click({$outputBoxMon.Text=""})
$ButtonMon.Add_Click({$outputBoxGcard.Text=""})
$ButtonMon.Add_Click({monitors})
$ButtonMon.Add_Click({graphics})
$Hardware.Controls.Add($ButtonMon)

The 4 separate event handlers for $ButtonMon.Click look a little fishy. Might be something happening with order of execution there. Try making it a single script block:

$ButtonMon.Add_Click({
    $outputBoxMon.Text=""
    $outputBoxGcard.Text=""
    monitors
    graphics
})

I removed them and still no joy :frowning:

If i remove the “| selec caption” i get the whole property display in the output box… So it’s baffling me why just the caption won’t display

Are you running PowerShell v2, by chance? If $card is an array, in PSv2, you’d get nothing when you tried to do $card.Caption (because arrays don’t have a Caption property.) In PSv3 or later, it’ll enumerate the array for you and give you the Caption properties of the elements in the array.

To be V2 compliant with arrays, you’d do this:

$card = get-wmiobject Win32_VideoController -ComputerName $HostName
$graphics = $card | Select-Object -ExpandProperty Caption