switch statement to calc dates from Import-CSV

I am trying to learn the switch statement, and I'm missing some basics.

For a collection imported from CSV, I want to determine for each row a date in the past, using Get-Date.AddDays(-n)

$list1 = Import-CSV "c:\ArchiveFileList1.csv

The columns used from the collection are:
MOVEUNIT - DAYS, MONTHS, or null
MOVENUM - integer with the number of days or months

I then want to apply AddDays(-n) to find the date in the paste.
(Files older than that will be deleted separate from this piece of code).

switch ($list1)
{
DAYS {(Get-Date).AddDays(-$_.MOVENUM); break}
MONTHS {(Get-Date).AddMonths(-$_.MOVENUM); break}
default {Write-Output "Days or Months not specified."}
}

If this method, once corrected, will work for this idea, I would also like to populate a pre-defined column in the collection with that date returned by Switch.

I know I have many issues currently.

Should the declaration have the collection, or the collection.column?
switch ($list1)
switch ($list1.MOVEUNIT)

How does  AddDays refer to the MOVENUM column for the corresponding row reading MOVEUNIT given row?
AddDays(-$_.MOVENUM)
AddDays(-$list1.MOVENUM)

 

  • Baby Steps. I see if I specify one element from my array the switch works.
    So then to apply Get-Date for each element, I will try a For Each, using switch one element at a time.
    --
    switch ($list1[3].MOVEUNIT)
    {
    DAYS {(Get-Date).AddDays(-$list1[3].MOVENUM); break}
    MONTHS {(Get-Date).AddMonths(-$list1[3].MOVENUM); break}
    default {Write-Output "Days or Months not specified."}
    }