I have a monthly report output by an FTP program into CSV format. The CSV file has headers and 3 columns:
1) a group name
2) the number of transfers that group made
3) the total size of all their transfers (in bytes)
Example (with headers and 6 rows of data for 7 rows total):
"monthly transfers","sum of monthly transfers","sum of file size""group1 (Prod to Dev)","26","11556381672""group2 (Prod to Dev)","5","348197396""group3 (Prod to Dev)","14","1272913379""group1 (Dev to Prod)","0","0""group2 (Dev to Prod)","1976","2036311426""group3 (Dev to Prod)","1","131"
I have been asked to write a script that will convert the bytes to megabytes and then sort based on group name and export the new data so auditors (non-technical people) can review it.
I've worked with Excel a bunch in Powershell (I.E. opening a com object and writing directly to a cell) and I'd prefer to do it that way, but the server this script needs to run on doesn't have MS Office installed and can't have anything else installed on it, so I'm trying to learn about import-csv and such. I've come up with this:
$file = "C:\ftp\ftp_report.csv" $csv = import-csv $file $csv | sort "monthly transfers"
The part I'm stuck on is converting that third column from bytes to megabytes. I know that in Powershell I can do "X / 1mb" to convert a number from bytes to megabytes, but I'm not sure of how best to do this in a specific column of a CSV file. Should I create a hash table? Should I count the number of rows and then do a "foreach" on
$csv[0].'sum of file size' / 1mb
?
Am I overthinking this and there's a really easy way to manipulate all values in a column?
Thank you in advance.
zarberg@gmail.com