Sorry, here is the script. Lines 87 - 100 is the conditional and actions that I cannot get to work.
Thanks
If (-NOT (Test-Path \\NCPSERVER\TCR_Share\ProjectsFolder\ProjectSandBox\etl\ToBeProcessed\* -Include qb_i*.csv)){
Exit
Write-Host -Message "CRAP"
}
Write-Host -BackgroundColor Blue -ForegroundColor Yellow -Message "Generating Invoice Batch"
# --- Create UNIQUE identifier for batch run
$BatchRunID = Get-Date -Format yyyyMMdd-HHmmss
# --- Define OUTPUT files
$ABCRollUpTestFile = "\\NCPSERVER\TCR_Share\ProjectsFolder\ProjectSandBox\etl\ToBeImported\"+$BatchRunID+"-ABCInvoiceRollUpTest.csv"
# --- Create NULL HASHES for work tables
$ABCInvoiceRollUpRow = @{}
# --- Not really sure WHAT these do :-)
[System.Collections.ArrayList] $ABCInvoiceRollUpTable = New-Object System.Collections.ArrayList($null)
$Header = 'Rec_Type','PO','Customer','Invoice','Ship','Date','B1','Name','Addr1','Addr2','City','State','Zip','Country','Line','Qty','Unit','Site','Carton'
Foreach ($InvoiceBatchFiles in Get-ChildItem -Path \\NCPSERVER\TCR_Share\ProjectsFolder\ProjectSandBox\etl\ToBePr~1 -Filter qb_i*.csv) {
$InvoiceArray += Import-Csv \\NCPSERVER\TCR_Share\ProjectsFolder\ProjectSandBox\etl\ToBePr~1\$InvoiceBatchFiles -Header $Header
#Rename-Item \\NCPSERVER\TCR_Share\ProjectsFolder\ProjectSandBox\etl\ToBePr~1\$InvoiceBatchFiles \\NCPSERVER\TCR_Share\ProjectsFolder\ProjectSandBox\etl\ToBePr~1\$BatchRunID-$InvoiceBatchFiles
}
# --- Create ABC Rollup Invoice HEADER and write to output fileut don't write it yet
$ABCInvoiceRollUpRow.Rec_Type = "NCP INVOICE"
$ABCInvoiceRollUpRow.PO = ""
$ABCInvoiceRollUpRow.Customer = "ABC.COM"
$ABCInvoiceRollUpRow.Invoice = $BatchRunID
$ABCInvoiceRollUpRow.Ship = ""
$ABCInvoiceRollUpRow.Date = Get-Date -Format d
$ABCInvoiceRollUpRow.B1 = ""
$ABCInvoiceRollUpRow.Name = ""
$ABCInvoiceRollUpRow.Addr1 = ""
$ABCInvoiceRollUpRow.Addr2 = ""
$ABCInvoiceRollUpRow.City = ""
$ABCInvoiceRollUpRow.State = ""
$ABCInvoiceRollUpRow.Zip = ""
$ABCInvoiceRollUpRow.Country = ""
$ABCInvoiceRollUpRow.Line = ""
$ABCInvoiceRollUpRow.Qty = ""
$ABCInvoiceRollUpRow.Unit = ""
$ABCInvoiceRollUpRow.Site = ""
$ABCInvoiceRollUpRow.Carton = ""
$ABCInvoiceRollUpTable.Add((New-Object PSObject -Property $ABCInvoiceRollUpRow))
Foreach ($InvoiceBatch in $InvoiceArray) {
# --- Check to see if Customer is ABC
If ($InvoiceBatch.Customer -eq "ABC.COM") {
# --- See if the ABC record is a Header or a Line
If (-NOT [string]::IsNullOrEmpty($InvoiceBatch.Unit)){
# --- It's a ABC LINE
If ($InvoiceBatch.Line -ne "Freight"){
$ABCInvoiceRollUpRow.Rec_Type = "NCP INVOICE"
$ABCInvoiceRollUpRow.PO = $InvoiceBatch.PO
$ABCInvoiceRollUpRow.Customer = "ABC.COM"
$ABCInvoiceRollUpRow.Invoice = $BatchRunID
$ABCInvoiceRollUpRow.Ship = ""
$ABCInvoiceRollUpRow.Date = Get-Date -Format d
$ABCInvoiceRollUpRow.B1 = ""
$ABCInvoiceRollUpRow.Name = ""
$ABCInvoiceRollUpRow.Addr1 = ""
$ABCInvoiceRollUpRow.Addr2 = ""
$ABCInvoiceRollUpRow.City = ""
$ABCInvoiceRollUpRow.State = ""
$ABCInvoiceRollUpRow.Zip = ""
$ABCInvoiceRollUpRow.Country = ""
# --- Need a lookup into the $ABCInvoiceRollUP table to see if LINE already exists
Write-Host "About to test"
Write-Host $InvoiceBatch.Line
If($ABCInvoiceRollUpTable.Contains($InvoiceBatch.Line)){
Write-Host "Yep!"
$ABCInvoiceRollUpRow.Qty = $ABCInvoiceRollUpRow.Qty + $InvoiceBatch.Qty
}
Else {
Write-Host "Nope!"
$ABCInvoiceRollUpRow.Line = $InvoiceBatch.Line
$ABCInvoiceRollUpRow.Qty = $InvoiceBatch.Qty
$ABCInvoiceRollUpRow.Unit = $InvoiceBatch.Unit
}
$ABCInvoiceRollUpTable.Add((New-Object PSObject -Property $ABCInvoiceRollUpRow))
}# If ($InvoiceBatch.Line -ne "Freight")
} #If (-NOT [string]::IsNullOrEmpty($InvoiceBatch.Unit))
}
}
# ---------------------------------------- OUTPUTS ---------------------------
# --- ABCInvoiceRollUpTest file output
$ABCInvoiceRollUpTable |
Select Rec_Type,PO,Customer,Invoice,Ship,Date,B1,Name,Addr1,Addr2,City,State,Zip,Country,Line,Qty,Unit,Site,Carton |
Export-Csv -Path $ABCRollUpTestFile -NoTypeInformation
(Get-Content $ABCRollUpTestFile | Select-Object -Skip 1) | Set-Content $ABCRollUpTestFile