SHARE
TWEET

Untitled

a guest Sep 16th, 2019 143 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Function Format-MerchReports {
  2.   <#
  3.   .SYNOPSIS
  4.   Reformats and combines Merch by Amazon sales reports
  5.  
  6.   .DESCRIPTION
  7.   1. Deletes the first 13 rows of each CSV in $csvPath
  8.   2. Combines the data from all the files
  9.   3. Adds column headers defined in $finalHeader
  10.   4. Outputs the file to $csvPath as formatted-Merchreports.csv
  11.  
  12.   .PARAMETER csvPath
  13.   Specifies the file system path the folder containing
  14.   the Merch by Amazon reports.
  15.  
  16.   .INPUTS
  17.   System.String. File path to the CSV Merch by Amazon reports.
  18.  
  19.   .OUTPUTS
  20.   CSV file to $csvPath with filename formatted-Merchreports.csv
  21.  
  22.   .EXAMPLE
  23.   Format-MerchReports -csvPath c:\mypath\
  24.  
  25.   .LINK
  26.  
  27.   #>
  28.  
  29.   [CmdletBinding()]
  30.       Param([string]$csvPath = 'c:\Reports\')
  31.           try
  32.               {
  33.                   $processedCSVs = $NULL
  34.                   $csvs = Get-ChildItem -Path $csvPath -Filter *.csv
  35.    
  36.                   $header = 'Blank','Date','ASIN','Name','Category 1',
  37.                       'Category 2','Category 3','Product Type','Transaction Type',
  38.                       'Sales Price','Sales Price Currency Code','Units',
  39.                       'Gross Earnings or Refunds'
  40.    
  41.                   $finalHeader = 'Date','ASIN','Name','Category 1',
  42.                       'Category 2','Category 3','Product Type','Transaction Type',
  43.                       'Sales Price','Sales Price Currency Code','Units',
  44.                       'Gross Earnings or Refunds'
  45.    
  46.                   foreach ($csv in $csvs) {
  47.                       $processedCSVs += Import-Csv -Path $csv -Delimiter ',' -Header $header |
  48.                           Select-Object -Skip 13 -Property $finalHeader
  49.                   }
  50.  
  51.                   $processedCSVs | Export-Csv -Path "$csvPath\formatted-Merchreports.csv" -NoTypeInformation    
  52.               }
  53.           catch
  54.               {
  55.                   "Error was $_"
  56.                   $line = $_.InvocationInfo.ScriptLineNumber
  57.                   "Error was in Line $line"
  58.               }
  59. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top