Show two rows in textbox without @{}

Welcome Forums General PowerShell Q&A Show two rows in textbox without @{}

Viewing 1 reply thread
  • Author
    Posts
    • #218400
      Participant
      Topics: 1
      Replies: 0
      Points: 11
      Rank: Member

      Im trying to output the following in a textbox

      $name = Get-WmiObject ‘Win32_ComputerSystem’ -ComputerName localhost | select -property name
      $bios = Get-WmiObject Win32_BIOS -ComputerName localhost | select serialnumber

      $txtbox.Text = $name ; $bios

      The result shows
      @{name=PC01}

      How can i show the $bios  in the same text box but in a second row and without @{name=}?

    • #218412
      Participant
      Topics: 4
      Replies: 2231
      Points: 5,414
      Helping Hand
      Rank: Community MVP

      Eduardo, welcome to Powershell.org. Please take a moment and read the very first post on top of the list of this forum: Read Me Before Posting! You’ll be Glad You Did!.

      When you post code or error messages or sample data or console output format it as code using the code tags “PRE“, please. Thanks in advance.

      You have a few options to avoid this … maybe like this:

      $name = Get-WmiObject 'Win32_ComputerSystem' -ComputerName localhost
      $bios = Get-WmiObject Win32_BIOS -ComputerName localhost
      
      $txtbox.Text = $($name.name) ; $($bios.serialnumber)

      or like this:

      $name = Get-WmiObject 'Win32_ComputerSystem' -ComputerName localhost | Select-Object -ExpandProperty name
      $bios = Get-WmiObject Win32_BIOS -ComputerName localhost | Select-Object -ExpandProperty serialnumber
      
      $txtbox.Text = $name; $bios

      BTW: Instead of Get-WmiObject you should use Get-CimInstance. 😉
      … and for the local computer you wouldn’t need to provide the parameter -ComputerName. 😉

Viewing 1 reply thread
  • You must be logged in to reply to this topic.