PowerShell -- Import csv, reformat date values, export csv
You need to use a calculated property with Select-Object
Try
Import-Csv foo.csv |
Select-Object @{Name = 'Date Created'; Expression = { '{0:yyyy-MM-dd}' -f [datetime]$_.'Date Created' }},
* -ExcludeProperty 'Date Created' |
Export-Csv -NoTypeInformation foo-new.csv
Easiest way to go about this is using a calculated property:
Import-Csv -Path C:\users\Abraham\Desktop\csvDate.csv |
Select-Object -Property @{
Name = "DateCreated"
Expression = {
([datetime]$_."Date Created").ToString("yyyy-MM-d")
}
}, ID, "Email Address", "First Name", "Last Name" # | Export-Csv ...
As for what you tried. . .you're basically de-selecting all your properties when piped to Foreach-Object
then trying to select what's not already there; hence why you get an empty csv.