Windows Vista Forums

-f operator
  1. #1


    Tibor Soos Guest

    -f operator

    Why and how does this work?

    PS I:\>Get-Date -f MMddyyHHmmss
    052708131411

    Normally the format pattern on the left side of -f, and the expression on
    the right:
    PS C:\> "{0:n}" -f 1234567
    1 234 567,00



    But on the example on the top it seems for me that it's the other way
    around. How does that work?

    --
    Tibor

      My System SpecsSystem Spec

  2. #2


    Keith Hill [MVP] Guest

    Re: -f operator

    "Tibor Soos" <TiborSoos@xxxxxx> wrote in message
    news:7AF31D8D-5E86-4F33-851C-A24229FAC765@xxxxxx

    > Why and how does this work?
    >
    > PS I:\>Get-Date -f MMddyyHHmmss
    > 052708131411
    >
    > Normally the format pattern on the left side of -f, and the expression on
    > the right:
    > PS C:\> "{0:n}" -f 1234567
    > 1 234 567,00
    >
    > But on the example on the top it seems for me that it's the other way
    > around. How does that work?
    Get-Date has a -Format parameter that your first example is supplying the
    arg MMddyyHHmmss. In PowerShell you only have to specify enough of the
    parameter name to disambiguate that parameter from any others on the cmdlet.
    So while the two invocations use -F the similarity is only superficial. One
    is a shortened parameter name while the other is a language operator.

    --
    Keith


      My System SpecsSystem Spec

  3. #3


    Tibor Soos Guest

    Re: -f operator

    Oh, that short form of parameters tricked me! Thanks a lot!
    --
    Tibor


    "Keith Hill [MVP]" wrote:

    > "Tibor Soos" <TiborSoos@xxxxxx> wrote in message
    > news:7AF31D8D-5E86-4F33-851C-A24229FAC765@xxxxxx

    > > Why and how does this work?
    > >
    > > PS I:\>Get-Date -f MMddyyHHmmss
    > > 052708131411
    > >
    > > Normally the format pattern on the left side of -f, and the expression on
    > > the right:
    > > PS C:\> "{0:n}" -f 1234567
    > > 1 234 567,00
    > >
    > > But on the example on the top it seems for me that it's the other way
    > > around. How does that work?
    >
    > Get-Date has a -Format parameter that your first example is supplying the
    > arg MMddyyHHmmss. In PowerShell you only have to specify enough of the
    > parameter name to disambiguate that parameter from any others on the cmdlet.
    > So while the two invocations use -F the similarity is only superficial. One
    > is a shortened parameter name while the other is a language operator.
    >
    > --
    > Keith
    >

      My System SpecsSystem Spec

  4. #4


    Alex K. Angelopoulos Guest

    Re: -f operator

    Keith, you need to be doing PowerShell seminars. ; )

    "Keith Hill [MVP]" <r_keith_hill@xxxxxx_no_spam_I> wrote in message
    news:5446D1C0-115E-4CA4-BC28-FF04D4E14F49@xxxxxx

    > "Tibor Soos" <TiborSoos@xxxxxx> wrote in message
    > news:7AF31D8D-5E86-4F33-851C-A24229FAC765@xxxxxx

    >> Why and how does this work?
    >>
    >> PS I:\>Get-Date -f MMddyyHHmmss
    >> 052708131411
    >>
    >> Normally the format pattern on the left side of -f, and the expression on
    >> the right:
    >> PS C:\> "{0:n}" -f 1234567
    >> 1 234 567,00
    >>
    >> But on the example on the top it seems for me that it's the other way
    >> around. How does that work?
    >
    > Get-Date has a -Format parameter that your first example is supplying the
    > arg MMddyyHHmmss. In PowerShell you only have to specify enough of the
    > parameter name to disambiguate that parameter from any others on the
    > cmdlet. So while the two invocations use -F the similarity is only
    > superficial. One is a shortened parameter name while the other is a
    > language operator.
    >
    > --
    > Keith

      My System SpecsSystem Spec

-f operator problems?

Similar Threads
Thread Thread Starter Forum Replies Last Post
-ne operator Simon Walsh PowerShell 3 23 Nov 2008
Operator Error dgmacmi Vista performance & maintenance 0 07 Apr 2008
What does the $() operator do? Kevin Buchan PowerShell 3 08 Feb 2008
-f Format Operator Guy Thomas PowerShell 7 13 Jun 2007
-replace operator Bob Weiner PowerShell 1 30 Jun 2006