-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFormat-MerchReports.ps1
59 lines (47 loc) · 1.95 KB
/
Format-MerchReports.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
Function Format-MerchReports {
<#
.SYNOPSIS
Reformats and combines Merch by Amazon sales reports
.DESCRIPTION
1. Deletes the first 13 rows of each CSV in $csvPath
2. Combines the data from all the files
3. Adds column headers defined in $finalHeader
4. Outputs the file to $csvPath as formatted-Merchreports.csv
.PARAMETER csvPath
Specifies the file system path the folder containing
the Merch by Amazon reports.
.INPUTS
System.String. File path to the CSV Merch by Amazon reports.
.OUTPUTS
CSV file to $csvPath with filename formatted-Merchreports.csv
.EXAMPLE
Format-MerchReports -csvPath c:\mypath\
.LINK
#>
[CmdletBinding()]
Param([string]$csvPath = 'c:\Reports\')
try
{
$processedCSVs = $NULL
$csvs = Get-ChildItem -Path $csvPath -Filter *.csv
$header = 'Blank','Date','ASIN','Name','Category 1',
'Category 2','Category 3','Product Type','Transaction Type',
'Sales Price','Sales Price Currency Code','Units',
'Gross Earnings or Refunds'
$finalHeader = 'Date','ASIN','Name','Category 1',
'Category 2','Category 3','Product Type','Transaction Type',
'Sales Price','Sales Price Currency Code','Units',
'Gross Earnings or Refunds'
foreach ($csv in $csvs) {
$processedCSVs += Import-Csv -Path $csv -Delimiter ',' -Header $header |
Select-Object -Skip 13 -Property $finalHeader
}
$processedCSVs | Export-Csv -Path "$csvPath\formatted-Merchreports.csv" -NoTypeInformation
}
catch
{
"Error was $_"
$line = $_.InvocationInfo.ScriptLineNumber
"Error was in Line $line"
}
}