duez
duez

Reputation: 3

powershell import-csv two times

This is possibly a silly question but i tried to import 2 csv-files with powershell. but when i try to write to the screen only the first one shows.

$connectivityCsvFile = @(Import-Csv "C:\connectivity.csv")
$logfileCsvFile = @(Import-Csv "C:\1-log.csv")

$logfileCsvFile    
$connectivityCsvFile

print-screen of output

if I change the $logfileCsvFile with $connectivityCsvFile then the connectivity-file is printed and not the logfile

anyone knows why?

Upvotes: 0

Views: 123

Answers (1)

Mike Zboray
Mike Zboray

Reputation: 40838

I think what PowerShell is doing is selecting the properties to show you based on the types in the first collection you are writing to output. The second collection has objects with entirely different properties and so the values default to blanks.

The lines

$logFileCsvFile
$connectivityCsvFile

don't really show you the values (at least that's not their primary effect). They cause the script to write the values to the output stream. The values in this stream are then displayed at the end of the command. Having an output stream with two different kinds of objects kind of messes up the default display behavior.

If you want to output to be print in a table format, you should use Format-Table (ft):

$logfileCsvFile | ft
$connectivityCsvFile | ft

Upvotes: 1

Related Questions