Output Box not displaying

This topic contains 4 replies, has 2 voices, and was last updated by  Dave Wyatt 2 years, 1 month ago.

  • Author
  • #37382

    Andy Smith

    Evening all

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

     function graphics {
    $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
    $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"
  • #37384

    Dave Wyatt

    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:

  • #37387

    Andy Smith

    I removed them and still no joy 🙁

  • #37396

    Andy Smith

    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

  • #37398

    Dave Wyatt

    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

You must be logged in to reply to this topic.