3

I am trying to analyze a lot of robocopy logs to have summaries in column instead of lines.

I gather data in an array of hashes which works fine. Each hash has the following structure:

Bytes_Copied   : 0
Bytes_FAILED   : 0
Source         : PROGRAM
Files_Total    : 582794

I am exporting them like that:

Bytes_Copied    Bytes_FAILED   Source      Files_Total   
------------    ------------   ------      -----------   
      1.006t           1.69m     TEAM           884194      

As I want to export them into a CSV I wish I was able to select the order of columns. This works when I "hard code" properties in the command:

$collectLines | Select-Object -Property Source,Date,Started,Ended,BpSec |
  Where-Object {$_.Source -eq 'TEAM'} |
  Export-Csv $ExportFileTeam -NoTypeInformation

As there are many more columns actually I had the idea to put them in a string to help choosing the order without touching code that works.

$ExportList = "Source,Date,Started,Ended,BpSec"

But I cannot make it to have the Select-Object take care of my string:

Select-Object -Property $ExportList

I tried many things with parentheses, braces, nothing works. Also I could not find a clue on the Internet.

1
  • 3
    "Source,Date,Started,Ended,BpSec" is one string, Select-Object -Property expects one string per property: $ExportList = "Source","Date","Started","Ended","BpSec" Commented Sep 1, 2015 at 15:18

1 Answer 1

5

You must specify the property list as an array of strings, not as a single string with comma-separated names:

$ExportList = 'Source', 'Date', 'Started', 'Ended', 'BpSec'
Sign up to request clarification or add additional context in comments.

1 Comment

That's it.. blushing for having missed that

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.