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

RB

Vista - -f Format Operator

Reply
 
06-12-2007   #1
Guy Thomas


 

-f Format Operator

I am a beginner, thus it's difficult to make many contributions amongst such
alumni.

It would probably only take a scripting expert 10 seconds to work out how
the -f format operator works, but it took me 30 minutes and zillions of
failures before I finally grasped how it aligns columns. Just in-case there
are any other newbies reading this forum I have a link to an article that I
wrote giving examples of the -f format operator.

http://www.computerperformance.co.uk..._-f_format.htm

Guy





My System SpecsSystem Spec
06-12-2007   #2
Jacques Barathon [MS]


 

Re: -f Format Operator

"Guy Thomas" <guy@computerperformance.co.uk> wrote in message
news:exupy1OrHHA.4836@TK2MSFTNGP05.phx.gbl...
>I am a beginner, thus it's difficult to make many contributions amongst
>such alumni.
>
> It would probably only take a scripting expert 10 seconds to work out how
> the -f format operator works, but it took me 30 minutes and zillions of
> failures before I finally grasped how it aligns columns. Just in-case
> there are any other newbies reading this forum I have a link to an article
> that I wrote giving examples of the -f format operator.
>
> http://www.computerperformance.co.uk..._-f_format.htm


Guy,

Thanks for sharing. If you don't mind, I will translate your article (or
part of it) in French to publish it in my blog -
http://janel.spaces.live.com. I will refer to your site for those of my
readers who want to see the original article.

Also, you should be aware of what format-table can provide with regard to
formatting output that may be much easier to manipulate in most typical
scenarios:

PS> get-eventlog -list

Note that table view is the default format used by PowerShell when you
display the list of event logs, so if you are happy with the default
properties you don't have to specify any formatting instruction. If you want
to display custom properties, you will have to specify them as part of the
format-table command (I will use ft which is a standard alias to
format-table):

PS> get-eventlog -list | ft log, overflowaction, max*

Note that max* will display all properties starting with max (in this case
there is only one matching this criteria).

If you want to see the columns automatically sized so they better use your
console width, use the -autowidth switch (or the -a shortcut):

PS> get-eventlog -list | ft log, overflowaction, max* -a

Finally, if you want to get rid of headers when you output the list, use
the -hideTableHeaders switch (or the -h shortcut):

PS> get-eventlog -list | ft log, over*, max* -a -h

Regards,
Jacques

My System SpecsSystem Spec
06-12-2007   #3
Josh


 

Re: -f Format Operator

On Jun 12, 8:30 am, "Guy Thomas" <g...@computerperformance.co.uk>
wrote:
> I am a beginner, thus it's difficult to make many contributions amongst such
> alumni.
>
> It would probably only take a scripting expert 10 seconds to work out how
> the -f format operator works, but it took me 30 minutes and zillions of
> failures before I finally grasped how it aligns columns. Just in-case there
> are any other newbies reading this forum I have a link to an article that I
> wrote giving examples of the -f format operator.
>
> http://www.computerperformance.co.uk..._-f_format.htm
>
> Guy


Hi Guy,

You can use PS's built-in format-table command to handle some of the
formatting work for you. Try:

get-eventlog -list | ft log,over*,max* -auto

ft is an alias for "format-table," and I truncated the OverflowAction
and MaximumKilobytes property names.

I like your use of the -f operator to get the columns to align to the
left. Does anyone know if there's a way to force format-table to do
this? Thanks.

~Josh

My System SpecsSystem Spec
06-12-2007   #4
Marcel J. Ortiz [MSFT]


 

Re: -f Format Operator

> I like your use of the -f operator to get the columns to align to the
> left. Does anyone know if there's a way to force format-table to do
> this? Thanks.


Yes, but you have to use hashtables to specify it. If you do 'get-help
format-table -full' and look at examples 5 and 6 you'll see the use of the
hashtable to specify the column name (Label) and an expression. Another
possible value is 'Alignment'. For example:

PS C:\testonly> get-eventlog -list | format-table
@{expression='LogDisplayName';alignment='left'},@{e='OverflowAction';a
='right'}

....




"Josh" <joshgavant@gmail.com> wrote in message
news:1181655869.177274.280610@j4g2000prf.googlegroups.com...
> On Jun 12, 8:30 am, "Guy Thomas" <g...@computerperformance.co.uk>
> wrote:
>> I am a beginner, thus it's difficult to make many contributions amongst
>> such
>> alumni.
>>
>> It would probably only take a scripting expert 10 seconds to work out how
>> the -f format operator works, but it took me 30 minutes and zillions of
>> failures before I finally grasped how it aligns columns. Just in-case
>> there
>> are any other newbies reading this forum I have a link to an article that
>> I
>> wrote giving examples of the -f format operator.
>>
>> http://www.computerperformance.co.uk..._-f_format.htm
>>
>> Guy

>
> Hi Guy,
>
> You can use PS's built-in format-table command to handle some of the
> formatting work for you. Try:
>
> get-eventlog -list | ft log,over*,max* -auto
>
> ft is an alias for "format-table," and I truncated the OverflowAction
> and MaximumKilobytes property names.
>
> I like your use of the -f operator to get the columns to align to the
> left. Does anyone know if there's a way to force format-table to do
> this? Thanks.
>
> ~Josh
>


My System SpecsSystem Spec
06-12-2007   #5
Guy Thomas


 

Re: -f Format Operator

"Jacques Barathon [MS]" <jbaratho@online.microsoft.com> wrote in message
news:%23RiHOYPrHHA.3456@TK2MSFTNGP02.phx.gbl...
> "Guy Thomas" <guy@computerperformance.co.uk> wrote in message
> news:exupy1OrHHA.4836@TK2MSFTNGP05.phx.gbl...
>>I am a beginner, thus it's difficult to make many contributions amongst
>>such alumni.
>>
>> It would probably only take a scripting expert 10 seconds to work out how
>> the -f format operator works, but it took me 30 minutes and zillions of
>> failures before I finally grasped how it aligns columns. Just in-case
>> there are any other newbies reading this forum I have a link to an
>> article that I wrote giving examples of the -f format operator.
>>
>> http://www.computerperformance.co.uk..._-f_format.htm

>
> Guy,
>
> Thanks for sharing. If you don't mind, I will translate your article (or
> part of it) in French to publish it in my blog -
> http://janel.spaces.live.com. I will refer to your site for those of my
> readers who want to see the original article.
>
> Also, you should be aware of what format-table can provide with regard to
> formatting output that may be much easier to manipulate in most typical
> scenarios:
>
> PS> get-eventlog -list
>
> Note that table view is the default format used by PowerShell when you
> display the list of event logs, so if you are happy with the default
> properties you don't have to specify any formatting instruction. If you
> want to display custom properties, you will have to specify them as part
> of the format-table command (I will use ft which is a standard alias to
> format-table):
>
> PS> get-eventlog -list | ft log, overflowaction, max*
>
> Note that max* will display all properties starting with max (in this case
> there is only one matching this criteria).
>
> If you want to see the columns automatically sized so they better use your
> console width, use the -autowidth switch (or the -a shortcut):
>
> PS> get-eventlog -list | ft log, overflowaction, max* -a
>
> Finally, if you want to get rid of headers when you output the list, use
> the -hideTableHeaders switch (or the -h shortcut):
>
> PS> get-eventlog -list | ft log, over*, max* -a -h
>
> Regards,
> Jacques


Dear Jacques

You are most welcome to publish my article in your Blog, indeed I would be
honoured. If you, or your readers find any errors, then do let me know.

Thanks for your comments on Format-table. While I was aware of it, I did
not know about the -h switch.

Guy


My System SpecsSystem Spec
06-12-2007   #6
Guy Thomas


 

Re: -f Format Operator


"Marcel J. Ortiz [MSFT]" <mosoto@online.microsoft.com> wrote in message
news:uMRbIaQrHHA.4180@TK2MSFTNGP04.phx.gbl...
>> I like your use of the -f operator to get the columns to align to the
>> left. Does anyone know if there's a way to force format-table to do
>> this? Thanks.

>
> Yes, but you have to use hashtables to specify it. If you do 'get-help
> format-table -full' and look at examples 5 and 6 you'll see the use of the
> hashtable to specify the column name (Label) and an expression. Another
> possible value is 'Alignment'. For example:
>
> PS C:\testonly> get-eventlog -list | format-table
> @{expression='LogDisplayName';alignment='left'},@{e='OverflowAction';a
> ='right'}
>
> ...
>
>
>
>
> "Josh" <joshgavant@gmail.com> wrote in message
> news:1181655869.177274.280610@j4g2000prf.googlegroups.com...
>> On Jun 12, 8:30 am, "Guy Thomas" <g...@computerperformance.co.uk>
>> wrote:
>>> I am a beginner, thus it's difficult to make many contributions amongst
>>> such
>>> alumni.
>>>
>>> It would probably only take a scripting expert 10 seconds to work out
>>> how
>>> the -f format operator works, but it took me 30 minutes and zillions of
>>> failures before I finally grasped how it aligns columns. Just in-case
>>> there
>>> are any other newbies reading this forum I have a link to an article
>>> that I
>>> wrote giving examples of the -f format operator.
>>>
>>> http://www.computerperformance.co.uk..._-f_format.htm
>>>
>>> Guy

>>
>> Hi Guy,
>>
>> You can use PS's built-in format-table command to handle some of the
>> formatting work for you. Try:
>>
>> get-eventlog -list | ft log,over*,max* -auto
>>
>> ft is an alias for "format-table," and I truncated the OverflowAction
>> and MaximumKilobytes property names.
>>
>> I like your use of the -f operator to get the columns to align to the
>> left. Does anyone know if there's a way to force format-table to do
>> this? Thanks.
>>
>> ~Josh
>>

>


Dear Marcel and Josh

Thank you for extending my knowledge, especially of hash tables which I do
find difficult to use.

Guy


My System SpecsSystem Spec
06-12-2007   #7
hecks@hotmail.co.uk


 

Re: -f Format Operator

On Jun 12, 8:34 pm, "Guy Thomas" <g...@computerperformance.co.uk>
wrote:
> "Jacques Barathon [MS]" <jbara...@online.microsoft.com> wrote in messagenews:%23RiHOYPrHHA.3456@TK2MSFTNGP02.phx.gbl...
>
>
>
> > "Guy Thomas" <g...@computerperformance.co.uk> wrote in message
> >news:exupy1OrHHA.4836@TK2MSFTNGP05.phx.gbl...
> >>I am a beginner, thus it's difficult to make many contributions amongst
> >>such alumni.

>
> >> It would probably only take a scripting expert 10 seconds to work out how
> >> the -f format operator works, but it took me 30 minutes and zillions of
> >> failures before I finally grasped how it aligns columns. Just in-case
> >> there are any other newbies reading this forum I have a link to an
> >> article that I wrote giving examples of the -f format operator.

>
> >>http://www.computerperformance.co.uk..._-f_format.htm

>
> > Guy,

>
> > Thanks for sharing. If you don't mind, I will translate your article (or
> > part of it) in French to publish it in my blog -
> >http://janel.spaces.live.com. I will refer to your site for those of my
> > readers who want to see the original article.

>
> > Also, you should be aware of what format-table can provide with regard to
> > formatting output that may be much easier to manipulate in most typical
> > scenarios:

>
> > PS> get-eventlog -list

>
> > Note that table view is the default format used by PowerShell when you
> > display the list of event logs, so if you are happy with the default
> > properties you don't have to specify any formatting instruction. If you
> > want to display custom properties, you will have to specify them as part
> > of the format-table command (I will use ft which is a standard alias to
> > format-table):

>
> > PS> get-eventlog -list | ft log, overflowaction, max*

>
> > Note that max* will display all properties starting with max (in this case
> > there is only one matching this criteria).

>
> > If you want to see the columns automatically sized so they better use your
> > console width, use the -autowidth switch (or the -a shortcut):

>
> > PS> get-eventlog -list | ft log, overflowaction, max* -a

>
> > Finally, if you want to get rid of headers when you output the list, use
> > the -hideTableHeaders switch (or the -h shortcut):

>
> > PS> get-eventlog -list | ft log, over*, max* -a -h

>
> > Regards,
> > Jacques

>
> Dear Jacques
>
> You are most welcome to publish my article in your Blog, indeed I would be
> honoured. If you, or your readers find any errors, then do let me know.
>
> Thanks for your comments on Format-table. While I was aware of it, I did
> not know about the -h switch.
>
> Guy


Another trick when using expressions to format tables is to use
padleft/-right on the column labels to create minimum widths. This
can be useful to tweak the -autowidth behaviour, which can sometimes
squeeze things too drastically.

-Hecks

My System SpecsSystem Spec
06-13-2007   #8
Guy Thomas


 

Re: -f Format Operator


<hecks@hotmail.co.uk> wrote in message
news:1181691391.418316.78200@o11g2000prd.googlegroups.com...
> On Jun 12, 8:34 pm, "Guy Thomas" <g...@computerperformance.co.uk>
> wrote:
>> "Jacques Barathon [MS]" <jbara...@online.microsoft.com> wrote in
>> messagenews:%23RiHOYPrHHA.3456@TK2MSFTNGP02.phx.gbl...
>>
>>
>>
>> > "Guy Thomas" <g...@computerperformance.co.uk> wrote in message
>> >news:exupy1OrHHA.4836@TK2MSFTNGP05.phx.gbl...
>> >>I am a beginner, thus it's difficult to make many contributions amongst
>> >>such alumni.

>>
>> >> It would probably only take a scripting expert 10 seconds to work out
>> >> how
>> >> the -f format operator works, but it took me 30 minutes and zillions
>> >> of
>> >> failures before I finally grasped how it aligns columns. Just in-case
>> >> there are any other newbies reading this forum I have a link to an
>> >> article that I wrote giving examples of the -f format operator.

>>
>> >>http://www.computerperformance.co.uk..._-f_format.htm

>>
>> > Guy,

>>
>> > Thanks for sharing. If you don't mind, I will translate your article
>> > (or
>> > part of it) in French to publish it in my blog -
>> >http://janel.spaces.live.com. I will refer to your site for those of my
>> > readers who want to see the original article.

>>
>> > Also, you should be aware of what format-table can provide with regard
>> > to
>> > formatting output that may be much easier to manipulate in most typical
>> > scenarios:

>>
>> > PS> get-eventlog -list

>>
>> > Note that table view is the default format used by PowerShell when you
>> > display the list of event logs, so if you are happy with the default
>> > properties you don't have to specify any formatting instruction. If you
>> > want to display custom properties, you will have to specify them as
>> > part
>> > of the format-table command (I will use ft which is a standard alias to
>> > format-table):

>>
>> > PS> get-eventlog -list | ft log, overflowaction, max*

>>
>> > Note that max* will display all properties starting with max (in this
>> > case
>> > there is only one matching this criteria).

>>
>> > If you want to see the columns automatically sized so they better use
>> > your
>> > console width, use the -autowidth switch (or the -a shortcut):

>>
>> > PS> get-eventlog -list | ft log, overflowaction, max* -a

>>
>> > Finally, if you want to get rid of headers when you output the list,
>> > use
>> > the -hideTableHeaders switch (or the -h shortcut):

>>
>> > PS> get-eventlog -list | ft log, over*, max* -a -h

>>
>> > Regards,
>> > Jacques

>>
>> Dear Jacques
>>
>> You are most welcome to publish my article in your Blog, indeed I would
>> be
>> honoured. If you, or your readers find any errors, then do let me know.
>>
>> Thanks for your comments on Format-table. While I was aware of it, I did
>> not know about the -h switch.
>>
>> Guy

>
> Another trick when using expressions to format tables is to use
> padleft/-right on the column labels to create minimum widths. This
> can be useful to tweak the -autowidth behaviour, which can sometimes
> squeeze things too drastically.
>
> -Hecks
>


I like the sound of 'pad'.
I am overcome with the kindness and depth of knowledge in this forum.

Guy


My System SpecsSystem Spec
Reply

RB


Thread Tools


Similar Threads for: -f Format Operator
Thread Forum
-f format Format-Table Format-List against Select PowerShell
-ne operator PowerShell
-f operator PowerShell
What does the $() operator do? PowerShell
Suggestion: 1 new operator (well, maybe 6...) PowerShell


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