locked
Measure-Object: error with Measure the contents of a CSV file (PS v5.1) RRS feed

  • Question

  • I am going through a tutorial  ("Example 5: Measure the contents of a CSV file") which demonstrates how to calculate average years of service of the employees of a company.

    I've created a test Excel file with the first row serving as a header with values EmpNo, Years - just as described in the tutorial.

    Then I issued the following command:

    import-csv C:\Users\user\Desktop\testexcel.xlsx | Measure-Object -Property years -Minimum -Maximum -Average

    Please note that I tried to use both "years" and "Years" as an argument (the tutorial uses "years").

    And got error:

    Measure-Object : The property "years" cannot be found in the input for any objects.
    At line:1 char:53
    + ... xcel.xlsx | Measure-Object -Property years -Minimum -Maximum -Average ...
    +                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidArgument: (:) [Measure-Object], PSArgumentException
        + FullyQualifiedErrorId : GenericMeasurePropertyNotFound,Microsoft.PowerShell.Commands.MeasureObjectCommand

    Is the tutorial outdated or is my CSV format incorrect (see printscreen)

    Thank you



    • Edited by Kamokoba Monday, January 20, 2020 10:28 AM
    Monday, January 20, 2020 10:19 AM

Answers

  • An XLSX file IS NOT a Csv file.

    Please read the following to understand why:

    https://en.wikipedia.org/wiki/Comma-separated_values

    An XLSX file is a binary file only readable by Excel and many custom libraries and tools.  A Csv is a text file in the format specified in the link.


    \_(ツ)_/

    • Marked as answer by Kamokoba Monday, January 20, 2020 10:48 AM
    Monday, January 20, 2020 10:45 AM

All replies

  • An XLSX file IS NOT a Csv file.

    Please read the following to understand why:

    https://en.wikipedia.org/wiki/Comma-separated_values

    An XLSX file is a binary file only readable by Excel and many custom libraries and tools.  A Csv is a text file in the format specified in the link.


    \_(ツ)_/

    • Marked as answer by Kamokoba Monday, January 20, 2020 10:48 AM
    Monday, January 20, 2020 10:45 AM
  • Thank you, I've converted xlsx to csv and now it works fine
    Monday, January 20, 2020 10:48 AM