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.
"Source,Date,Started,Ended,BpSec"is one string,Select-Object -Propertyexpects one string per property:$ExportList = "Source","Date","Started","Ended","BpSec"