Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - Formating objects

Reply
 
Old 09-09-2007   #1 (permalink)
Shay Levi


 
 

Formating objects

I want to collect info from various servers and output to the console via
format-table.
Say the info I'm collecting is : Property1,Property2,Property3,Property4

I want the output to look like (when formatted with format-table):

Property1 Property2 Property3 Property4
--------- --------- --------- ---------
Value1 Value2 Value3 Value4
Value1 Value2 Value3 Value4
Value1 Value2 Value3 Value4
Value1 Value2 Value3 Value4
(...)


I used System.Management.Automation.PSObject and added new NoteProperty with
Add-Member
but the final output repeats itself for each server:


Property1 Property2 Property3 Property4
--------- --------- --------- ---------
Value1 Value2 Value3 Value4
Value1 Value2 Value3 Value4
(...)

Property1 Property2 Property3 Property4
--------- --------- --------- ---------
Value1 Value2 Value3 Value4
Value1 Value2 Value3 Value4
(...)


I can emit the property names once (header row), and then use [string]::format("{0}
{1}", $_.prop1 ,$_.prop2) to emit each
table row, but I prefer format-table as it supports the -autosize parameter.



Shay
http://scriptolog.blogspot.com



My System SpecsSystem Spec
Old 09-09-2007   #2 (permalink)
Keith Hill


 
 

Re: Formating objects

"Shay Levi" <no@xxxxxx> wrote in message news:8766a9446bc58c9c106e790b3d0@xxxxxx
Quote:

>I want to collect info from various servers and output to the console via
> format-table.
> Say the info I'm collecting is : Property1,Property2,Property3,Property4
>
> I want the output to look like (when formatted with format-table):
>
> Property1 Property2 Property3 Property4
> --------- --------- --------- ---------
> Value1 Value2 Value3 Value4
> Value1 Value2 Value3 Value4
> Value1 Value2 Value3 Value4
> Value1 Value2 Value3 Value4
> (...)
>
>
> I used System.Management.Automation.PSObject and added new NoteProperty with
> Add-Member
> but the final output repeats itself for each server:
>
>
> Property1 Property2 Property3 Property4
> --------- --------- --------- ---------
> Value1 Value2 Value3 Value4
> Value1 Value2 Value3 Value4
> (...)
>
> Property1 Property2 Property3 Property4
> --------- --------- --------- ---------
> Value1 Value2 Value3 Value4
> Value1 Value2 Value3 Value4
> (...)
>
>
> I can emit the property names once (header row), and then use [string]::format("{0}
> {1}", $_.prop1 ,$_.prop2) to emit each
> table row, but I prefer format-table as it supports the -autosize parameter.
I can get the basic scenario to work:

PS C:\> gps w* | %{$obj = new-object psobject;add-member -inp $obj NoteProperty
Prop1 $_.Name;add-member -inp $obj NoteProperty Prop2 $_.Id; $obj} | ft -auto

Prop1 Prop2
----- -----
WindowClippings_x86 3248
wininit 612
winlogon 768

I think we need to see how you are collecting and adding the server info into the psobject.

--
Keith

My System SpecsSystem Spec
Old 09-09-2007   #3 (permalink)
Shay Levi


 
 

Re: Formating objects

Oh.. man 10Q

Shay
http://scriptolog.blogspot.com


Quote:

> "Shay Levi" <no@xxxxxx> wrote in message
> news:8766a9446bc58c9c106e790b3d0@xxxxxx
>
Quote:

>> I want to collect info from various servers and output to the console
>> via
>> format-table.
>> Say the info I'm collecting is :
>> Property1,Property2,Property3,Property4
>> I want the output to look like (when formatted with format-table):
>>
>> Property1 Property2 Property3 Property4
>> --------- --------- --------- ---------
>> Value1 Value2 Value3 Value4
>> Value1 Value2 Value3 Value4
>> Value1 Value2 Value3 Value4
>> Value1 Value2 Value3 Value4
>> (...)
>> I used System.Management.Automation.PSObject and added new
>> NoteProperty with Add-Member but the final output repeats itself for
>> each server:
>>
>> Property1 Property2 Property3 Property4
>> --------- --------- --------- ---------
>> Value1 Value2 Value3 Value4
>> Value1 Value2 Value3 Value4
>> (...)
>> Property1 Property2 Property3 Property4
>> --------- --------- --------- ---------
>> Value1 Value2 Value3 Value4
>> Value1 Value2 Value3 Value4
>> (...)
>> I can emit the property names once (header row), and then use
>> [string]::format("{0}
>> {1}", $_.prop1 ,$_.prop2) to emit each
>> table row, but I prefer format-table as it supports the -autosize
>> parameter.
> I can get the basic scenario to work:
>
> PS C:\> gps w* | %{$obj = new-object psobject;add-member -inp $obj
> NoteProperty Prop1 $_.Name;add-member -inp $obj NoteProperty Prop2
> $_.Id; $obj} | ft -auto
>
> Prop1 Prop2
>
> ----- -----
Quote:

>> WindowClippings_x86 3248
>> wininit 612
>> winlogon 768
>> I think we need to see how you are collecting and adding the server
>> info into the psobject.
>>
>> --
>> Keith

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Why was formating unsuccessful? Vista General
Formating HD Vista installation & setup
Formating Help General Discussion
HDD Formating Vista hardware & devices
Formating my PC Vista hardware & devices


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46