Forum Discussion

Kennethjn's avatar
Kennethjn
Copper Contributor
Nov 03, 2020

Export Import CSV - help please :)

Hi Everyone

 

I am currently creating a script that consists of a lot of small tasks, ending with the result being an Excel Report for the management team. But one part is giving me some trouble, so new i seek your help.

 

I have a number of CSV filers with the following rows:

"computer";"lastseen";"doccount"

 

I am only interested in the "computer" row, which contains computer names on client machines.

I need to end up with a CSV file with only that row + the column data. I have been trying to do the following:

 

 

Get-content -Path Pathtosource\sourcefile.csv | Select-Object -Property computer | Export-Csv -path Pathtodestination\destinationfile.csv -NoTypeInformation

 

 

 

To get it done in one command. But all i get is a CSV file with the text "computer" and nothing else. All the column data is missing.

 

I have been trying this also:

 

 

$ElasticBDContent = Get-content -Path PathtoSource\Sourcefile.csv
$ElasticBDContent = $ElasticBDContent | Select-Object -Property computer  
$ElasticBDContent | Export-Csv -path PathtoDestination\Destinationfile.csv -NoTypeInformation

 

 

 

Giving me the exact same result, a CSV file with the following content:

"computer"

 

This is the content i am looking for:

"computer"

"computer1"

"computer2"

"computer3"

 

Can anyone give an example on how to achieve this?

Any help is much appreciated.

 

Thanks in advance.

 

  • Kennethjn's avatar
    Kennethjn
    Nov 04, 2020

    I found the issue to simply being me missing the -Delimiter option on the import-csv command.

    I added -Delimiter ";", since it is the seperator in the csv file, and things are working now.

  • Every time you run the Export-CSV cmdlet you are effectively overwriting the file. Use the -Append switch as an easy fix.

    • Kennethjn's avatar
      Kennethjn
      Copper Contributor

      I found the issue to simply being me missing the -Delimiter option on the import-csv command.

      I added -Delimiter ";", since it is the seperator in the csv file, and things are working now.

    • Kennethjn's avatar
      Kennethjn
      Copper Contributor

      Hi Vasil

       

      I have tried to apply the -Append option, but it gives me the same result.

      A file with one "Computer" row and no computer names.

       

      Any other suggestions on what i am doing wrong?

Resources