-1

Im playing around with a GUI for WMI in powershell script. How do i format a PsObject to output in a multiline textbox so that each property of the PsObject is on its own line?

enter image description here

This is for my own learning purposes - I know there are tools out there for WMI collection :)

Vynce82
  • 119
  • 3
  • 15

1 Answers1

2

You can loop through the properties in your PSObject with ForEach-Object or use inline Format-List as suggested by @Theo

here's the sample code snippet to suite your requirement

$Form = New-Object System.Windows.Forms.Form
$Form.Size = New-Object System.Drawing.Size(400,400)
$Form.StartPosition = "CenterScreen"

$objTextBox1 = New-Object System.Windows.Forms.TextBox 
$objTextBox1.Multiline = $True;
$objTextBox1.Location = New-Object System.Drawing.Size(10,10) 
$objTextBox1.Size = New-Object System.Drawing.Size(300,400)
$objTextBox1.Scrollbars = "Vertical" 

$Form.Controls.Add($objTextBox1)

$output = Get-ComputerInfo -Property "os*"

$output.PSObject.Properties | ForEach-Object {
    $objTextBox1.Text = $objTextBox1.Text + "$($_.Name): $($_.Value)`r`n";
    #Write-Host "$($_.Name): $($_.Value)`r`n" 
}

$form.ShowDialog()| Out-Null 
Kundan
  • 1,394
  • 1
  • 13
  • 26