![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
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.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| 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 Specs![]() |
| | #2 (permalink) |
| 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 Specs![]() |
![]() |
| 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 |