I have a CSV file I import, and I need to change the format of a column (backed_up_ts) to remove the original data in the column and replace it with the updated format.
The original data for each row in the column looks like this:
Tue Sep 13 07:46:26 MDT 2016
The first part of my code formats every row so that it can be compared to a date:
$csv = Import-Csv -Path "C:\Users\user\Desktop\NewReport.csv" | Select display_client_name, backed_up_ts
$csv = foreach ($budate in $csv.backed_up_ts) {
$budate = $budate.Substring(3)
$budate = $budate.Replace("MDT", "")
$budate = $budate.Replace("MST", "")
$budate = $budate.Split(" ")
$budate = $budate[1] + " " + $budate[2] + " " + $budate[5]
$budate = ($budate | Get-Date -Format d)
From here I need to take the updated format (in the $budate value) and replace the original data in the $csv.backed_up_ts array.
However, the value of $budate is only the last value of the object in the foreach loop (3/30/16).
The value of $csv.backed_up_ts remains in the array in its original format (Wednesday, August 30th, EST, 2016).
I need the original array $csv.backed_up_ts to be replaced by the coordinating values created by the $budate.
Thanks.