Forum Discussion
AndiPsh180
Dec 21, 2021Copper Contributor
How construct a variable that works with export-csv?
Hello, I have a small csv file that I import in Powershell into a variable. Here it is (as I can't seem to upload a file): "RGG","BAS","IMT"
"keepass","webex","firefox"
"acrobat","ciscoan...
Dec 23, 2021
Usually you create an array with all the fields (colums) that you need and export it to a .csv using export-csv with the -NoTypeInformation parameter.
Example export to csv with a list of files in c:\temp
[array]$contents=Get-ChildItem c:\temp
$contents | export-csv -Path c:\temp\x.csv -Delimiter ';' -NoTypeInformation
Example export to csv with a list of files in c:\temp
[array]$contents=Get-ChildItem c:\temp
$contents | export-csv -Path c:\temp\x.csv -Delimiter ';' -NoTypeInformation
- AndiPsh180Dec 23, 2021Copper ContributorHello,
thank you for looking into this.
When I pull contents from my small csv file into a variable, I have no problem to export it again.
However, as I need to get things from here and there, strings mostly, I figured I would construct a variable just like the one I get after importing my csv file.
But that does not work. As long as I pull objects into a variable it is okay. But constructing a variable and putting strings from different places into it seems impossible.
So far I helped myself by writing into a file, knowing that the data in csv must be homogenous troughout.
It would have been elegant to construct the variable first as an object, give it the noteproperties (members) I need and only do one export-csv in the end.
Good New Year 2022 to you - in any case.