I have a couple of CSV files I have to merge, and purge of duplicates. The merging and purging I figured out. When I run my script it creates a new file in ./merged/ folder called merged.csv It then gets rid of duplicate barcodes and creates a new CSV called cleaned.csv in the working folder.
What I am having a problem with is renaming this cleaned.csv file as morning.csv, afternoon.csv, night.csv depending on the time it was created, i.e if created before 13:00 morning.csv, between 13:00-19:00 afternoon.csv, and any later night.csv.
#This line removes duplicate entries from the merged.csv and creates a new file called cleaned.csv in the working folder.
$inputCsv = Import-Csv ./merged/merged.csv | Sort-Object Barcode -Unique
$inputCsv | Export-Csv cleaned.csv -NoTypeInformation
Is there an easy way to do this in PS?
All you need to do is assign the filename based off of the time.
# This line removes duplicate entries from the merged.csv and
# creates a new file called cleaned.csv in the working folder.
$inputCsv = Import-Csv ./merged/merged.csv | Sort-Object Barcode -Unique
$thisHour = [DateTime]::Now.Hour
$exportFileName = # We can assign $exportFieldName based off a conditional
if ($thisHour -le 13) { # If the hour was less then 13
"morning.csv" # it's morning
} elseif ($thisHour -le 18) { # If it was less than 18
"afternoon.csv" # it's afternoon
} else { # otherwise
"night.csv" # it's night.
}
$inputCsv | Export-CSV -Path $exportFileName -NoTypeInformation