Author Posts

April 7, 2016 at 10:25 am

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)

April 7, 2016 at 10:37 am

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
})

April 7, 2016 at 10:40 am

I removed them and still no joy 🙁

April 7, 2016 at 1:44 pm

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

April 7, 2016 at 4:11 pm

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