Powershell Script - Sorting the output in a logical order

Nick Collins
Nick Collins used Ask the Experts™
on
Good Afternoon,

I currently have a power shell script that extracts data from a CSV source file and writes a new output file.

Script -

CSV Source File:

Output File:

I want to able to the sort the output file into the following order based on the headings below

1. Order Number
2. Please enter either the Plot Number, Garage Number or an area where the work is being done?
3. the following scaffolding which is either

So the new output file will look this

"HV_000024_1150980","189 188 plot ","Handing-Over"
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2014
Commented:
Well, they are rather verbose header names, but that's not too important.  You can specify the order of properties with a Select-Object command.  Change the last line of your script as follows.
$rec | Select-Object "Order Number:",
                      "Please enter either the Plot Number, Garage Number or an area where the work is being done?",
                      "the following scaffolding which is either" |
 Export-Csv -Path D:\iauditor_exports_folder\Email_Process\Test\AuditPlot_HV_Type.txt -NoTypeInformation

Open in new window


Edit:  corrected order
Top Expert 2014
Commented:
You could also change the name of headers using something like this.
$rec | Select-Object @{n="OrderNo";e={$_."Order Number:"}},
                     @{n="Location";e={$_."Please enter either the Plot Number, Garage Number or an area where the work is being done?"}},
                     @{n="ScaffoldingType";e={$_."the following scaffolding which is either"}} |
 Export-Csv -Path D:\iauditor_exports_folder\Email_Process\Test\AuditPlot_HV_Type.txt -NoTypeInformation

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial