Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

accessing properties with foreach-object versus format-table

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 07-09-2007   #1 (permalink)
Hal Rottenberg
Guest


 

accessing properties with foreach-object versus format-table

Should there be any difference in these two statements, performance-
wise? The second one is easier to read, IMO, and I'd like to know if
there are cases where I would not want to use it.

# Get-WMIObject Win32_Printer | foreach-object{$_.Name}

# Get-WMIObject Win32_Printer | format-table name


My System SpecsSystem Spec
Old 07-09-2007   #2 (permalink)
klumsy@xtra.co.nz
Guest


 

Re: accessing properties with foreach-object versus format-table

On Jul 9, 6:14 am, Hal Rottenberg <halr9...@gmail.com> wrote:
> Should there be any difference in these two statements, performance-
> wise? The second one is easier to read, IMO, and I'd like to know if
> there are cases where I would not want to use it.
>
> # Get-WMIObject Win32_Printer | foreach-object{$_.Name}
>
> # Get-WMIObject Win32_Printer | format-table name


on the screen the differences should be minimal.. format-table just
directs the formater (which takes the dotnet object in the pipeline
and formats them to fit in the console screen), to format the data a
certian way.. (here a table with one column) with the foreach you are
just outputting an array of strings, that happen to be the name and
they get formatted automatically

you could also play with

Get-WMIObject Win32_Printer | select name

again the formatting is done automatically.

one negative thing about format-* cmdlets is the pipeline data gets
destroyed , so while it may look fine on the screen. if you wanted to
do something with it later. its no good
i.e
$a =Get-WMIObject Win32_Printer | format-table name
$a | gm

-Karl

My System SpecsSystem Spec
Closed Thread

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
RE: How to convert Table-Format Data to CSV-Format? Kiron PowerShell 0 07-25-2008 05:47 PM
RE: How to convert Table-Format Data to CSV-Format? Kiron PowerShell 0 07-25-2008 03:19 PM
foreach, foreach-object & begin/process/end scriptblock clauses... Clint Bergman PowerShell 12 05-16-2007 05:30 PM
Difference in semantics of for, foreach and foreach-object Andrew Watt [MVP] PowerShell 3 01-26-2007 12:46 PM
Format Table and Properties. Brandon Shell PowerShell 2 08-16-2006 10:08 AM


Vistax64.com 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 2005-2008

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 47 48 49 50 51