I am trying to display the contents of column 1 and 2 in a CSV file. When I used the code below,
$csv = Import-Csv C:transfer.csv
$csv | Export-Csv transfer2.csv -NoTypeInformation
$csv | Select-Object col1, col2 ## This line returns the header col1, col2 but there is no data.
Transfer2.csv does contain data from transfer1.scv in column 1 & 2. But if I use Select-Object col1, col2, column1 and 2 come back completely empty. There was no error message. What am I doing wrong? What do I need to do to show contents of column 1 and 2 from transfer.csv?
Thanks for the feedback. I am simply trying to display the contents of column1 and column 2 of transfer.csv to see if the data is read correctly. Ultimately, what I am trying to do is use column 1 and 2 of a CSV file as the input variables to a function which will write the result to column3. But I can’t even seem to get the contents of column1 and 2 and I am not sure what I am doing wrong.
When dealing with a CSV, Select-Object treats the COLUMN HEADERS as properties. You you could Select Source, Destination, and Status, because those are your column headers. But “Col1” isn’t a thing. That’s why - as noted above - you’re getting blanks. Select-Object treats non-existent properties as new, blank properties, and outputs them.