SOLVED

Export Import CSV - help please :)

%3CLINGO-SUB%20id%3D%22lingo-sub-1849466%22%20slang%3D%22en-US%22%3EExport%20Import%20CSV%20-%20help%20please%20%3A)%3C%2Fimg%3E%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1849466%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20Everyone%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20am%20currently%20creating%20a%20script%20that%20consists%20of%20a%20lot%20of%20small%20tasks%2C%20ending%20with%20the%20result%20being%20an%20Excel%20Report%20for%20the%20management%20team.%20But%20one%20part%20is%20giving%20me%20some%20trouble%2C%20so%20new%20i%20seek%20your%20help.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20a%20number%20of%20CSV%20filers%20with%20the%20following%20rows%3A%3C%2FP%3E%3CP%3E%22computer%22%3B%22lastseen%22%3B%22doccount%22%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20am%20only%20interested%20in%20the%20%22computer%22%20row%2C%20which%20contains%20computer%20names%20on%20client%20machines.%3C%2FP%3E%3CP%3EI%20need%20to%20end%20up%20with%20a%20CSV%20file%20with%20only%20that%20row%20%2B%20the%20column%20data.%20I%20have%20been%20trying%20to%20do%20the%20following%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3EGet-content%20-Path%20Pathtosource%5Csourcefile.csv%20%7C%20Select-Object%20-Property%20computer%20%7C%20Export-Csv%20-path%20Pathtodestination%5Cdestinationfile.csv%20-NoTypeInformation%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ETo%20get%20it%20done%20in%20one%20command.%20But%20all%20i%20get%20is%20a%20CSV%20file%20with%20the%20text%20%22computer%22%20and%20nothing%20else.%20All%20the%20column%20data%20is%20missing.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20been%20trying%20this%20also%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-applescript%22%3E%3CCODE%3E%24ElasticBDContent%20%3D%20Get-content%20-Path%20PathtoSource%5CSourcefile.csv%0A%24ElasticBDContent%20%3D%20%24ElasticBDContent%20%7C%20Select-Object%20-Property%20computer%20%20%0A%24ElasticBDContent%20%7C%20Export-Csv%20-path%20PathtoDestination%5CDestinationfile.csv%20-NoTypeInformation%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EGiving%20me%20the%20exact%20same%20result%2C%20a%20CSV%20file%20with%20the%20following%20content%3A%3C%2FP%3E%3CP%3E%22computer%22%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThis%20is%20the%20content%20i%20am%20looking%20for%3A%3C%2FP%3E%3CP%3E%22computer%22%3C%2FP%3E%3CP%3E%22computer1%22%3C%2FP%3E%3CP%3E%22computer2%22%3C%2FP%3E%3CP%3E%22computer3%22%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ECan%20anyone%20give%20an%20example%20on%20how%20to%20achieve%20this%3F%3C%2FP%3E%3CP%3EAny%20help%20is%20much%20appreciated.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%20in%20advance.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1849466%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3Ecsv%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1850158%22%20slang%3D%22en-US%22%3ERe%3A%20Export%20Import%20CSV%20-%20help%20please%20%3A)%3C%2Fimg%3E%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1850158%22%20slang%3D%22en-US%22%3E%3CP%3EEvery%20time%20you%20run%20the%20Export-CSV%20cmdlet%20you%20are%20effectively%20overwriting%20the%20file.%20Use%20the%20-Append%20switch%20as%20an%20easy%20fix.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1852591%22%20slang%3D%22en-US%22%3ERe%3A%20Export%20Import%20CSV%20-%20help%20please%20%3A)%3C%2Fimg%3E%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1852591%22%20slang%3D%22en-US%22%3E%3CP%3EI%20found%20the%20issue%20to%20simply%20being%20me%20missing%20the%20-Delimiter%20option%20on%20the%20import-csv%20command.%3C%2FP%3E%3CP%3EI%20added%20-Delimiter%20%22%3B%22%2C%20since%20it%20is%20the%20seperator%20in%20the%20csv%20file%2C%20and%20things%20are%20working%20now.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1852168%22%20slang%3D%22en-US%22%3ERe%3A%20Export%20Import%20CSV%20-%20help%20please%20%3A)%3C%2Fimg%3E%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1852168%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20Vasil%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20tried%20to%20apply%20the%20-Append%20option%2C%20but%20it%20gives%20me%20the%20same%20result.%3C%2FP%3E%3CP%3EA%20file%20with%20one%20%22Computer%22%20row%20and%20no%20computer%20names.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAny%20other%20suggestions%20on%20what%20i%20am%20doing%20wrong%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E
New Contributor

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.

 

3 Replies

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

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?

best response confirmed by Kennethjn (New Contributor)
Solution

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.