# Displaying Objects

**URL:** <https://forums.powershell.org/t/displaying-objects/1631>\
**Category:** PowerShell Help\
**Created:** [May 16, 2013, 6:53pm UTC](https://forums.powershell.org/t/displaying-objects/1631 "2013-05-16T18:53:14Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![veroli](https://avatars.discourse-cdn.com/v4/letter/v/ac91a4/32.png) [@veroli](https://forums.powershell.org/u/veroli)\
**Post date:** [May 16, 2013, 6:53pm UTC](https://forums.powershell.org/t/displaying-objects/1631/1 "2013-05-16T18:53:14Z")

</div>

Hello,

I am using a WMI query to pull back fixed disk properties of remote server

$disks = (Get-WmiObject -class win32\_logicaldisk -computername $item -filter “drivetype=3”)

$item is the name of a remote machine

i then create a new object and i want to add a member to that object that displays the drive id and the size in GB by doing the following.

$output | Add-Member NoteProperty Hard\_Disks $disks | select -property @{n=‘Drive’;e={$_.DeviceID}}, @{n=‘size(GB)’;e={“{0:N2}” -f $($_.Size Â / 1GB)}}

If Â I try and then display this in a text box on a form instead a list of the disks and their sizes i get

Hard\_Disks=System.Object

Instead of a list of the disks, if i just try and output this at the shell i get the root path and a device id instead of the disk information.

This is a similar problem as requested in the scripting games i know, but it just happens to coincide with an inventory script i am working. I am not sure if i am refencing the object incorrectly. The type of output i am looking for is

c: Â Â Â Â Â Â 250

d: Â Â Â Â Â 10

e: Â Â Â Â Â 50

hope that makes sense any help appreciated.

regards

Dan

&nbsp;

---

<div class="post-metadata">

**Author:** ![davotronic5000](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/davotronic5000/32/956_2.png) [@davotronic5000](https://forums.powershell.org/u/davotronic5000)\
**Post date:** [May 16, 2013, 7:55pm UTC](https://forums.powershell.org/t/displaying-objects/1631/2 "2013-05-16T19:55:30Z")

</div>

I think you may be seeing something that I have had myself recently trying to output an object in to an event. Â If you convert the object to a string it should display correctly in the text box.

You can do this by piping the object in to the Out-String CMDlet.

---

<div class="post-metadata">

**Author:** ![veroli](https://avatars.discourse-cdn.com/v4/letter/v/ac91a4/32.png) [@veroli](https://forums.powershell.org/u/veroli)\
**Post date:** [May 16, 2013, 8:38pm UTC](https://forums.powershell.org/t/displaying-objects/1631/3 "2013-05-16T20:38:21Z")

</div>

Thanks Dave,

&nbsp;

i tried piping it out-string but still having the same result in the text box

---

<div class="post-metadata">

**Author:** ![poshoholic](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/poshoholic/32/884_2.png) [@poshoholic](https://forums.powershell.org/u/poshoholic)\
**Post date:** [May 16, 2013, 11:34pm UTC](https://forums.powershell.org/t/displaying-objects/1631/4 "2013-05-16T23:34:09Z")

</div>

I would take a different approach. Â Once you have the data you want in $disks, convert that into a string table with the values you care about, then strip off the header rows. Â Like this:

$tableAsString = $disks | ft @{Name=‘Drive’;Expression={$_.DeviceId}},@{Name=‘Size(GB)’;Expression={‘{0:N2}’ -f ($_.Size / 1GB)}} -AutoSize | Out-String

$tableAsString -replace ‘^\s+|\s+$’ -split “\r\n|\r|\n” | Select-Object -Skip 2

The results of the second command are what you will want to assign to the text box on your form.

---

<div class="post-metadata">

**Author:** ![veroli](https://avatars.discourse-cdn.com/v4/letter/v/ac91a4/32.png) [@veroli](https://forums.powershell.org/u/veroli)\
**Post date:** [May 20, 2013, 7:16pm UTC](https://forums.powershell.org/t/displaying-objects/1631/5 "2013-05-20T19:16:32Z")

</div>

Apologies for the delay this worked great, thanks poshoholic.

My next question is :

i have a number of WMI queries that put into a new object and then out put this to a fiel or screen. The problem i have is i want to just list the headings once, for example

Servername, disks, memory, ipaddress

and then under the heading list the information on a new line so if i want i can export to csv or just display the table. at the moment i do the following.

$output = New-Object PSObject  
$output | Add-Member NoteProperty Name ($system.DNSHostName)  
$output | Add-Member NoteProperty CPU ($system.NumberOfProcessors)  
$output | Add-Member NoteProperty OS ($OS.Caption)  
$output | Add-Member NoteProperty OS\_Serial\_Number ($os.serialnumber)

&nbsp;

in a for loop but this then runs the above code for each server in the for loop and doesnt just list each element on one line .

so what i want to see is

Server Â Â Â Â Â CPU Â Â Â Â OS Â Â Â Â Â OS\_serial

servera Â Â Â Â Â 1 Â Â Â Â Â Â Â 2008 Â Â xxxxx

serverb Â Â Â Â 4 Â Â Â Â Â Â Â 2008 Â Â yyyyyy

etc etc

&nbsp;

at the moment i get

Server: Â servera

cpu : 1

os: 2008

os\_serial: xxx

Server: serverb

cpu: 4

os:2008

os\_serial: yyyy

&nbsp;

regards Dan

&nbsp;

&nbsp;

---

<div class="post-metadata">

**Author:** ![poshoholic](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/poshoholic/32/884_2.png) [@poshoholic](https://forums.powershell.org/u/poshoholic)\
**Post date:** [May 20, 2013, 11:00pm UTC](https://forums.powershell.org/t/displaying-objects/1631/6 "2013-05-20T23:00:05Z")

</div>

You can force your loop to output in a table like this:  
`$(foreach {$a in $b) {`

`
Do stuff in here
`

`}) | Format-Table`  
If PowerShell is defaulting to list output, it is likely due to the number of columns that would appear in the output (PSObjects default to tabular output with 4 columns or less; list output otherwise).

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:57pm UTC](https://forums.powershell.org/t/displaying-objects/1631/7 "2024-05-16T20:57:49Z")

</div>


