All,
I have a .csv with three columns A B and C
Column A is named “Serial”
Colum B is named “Customer”
Column C is named “Seat”
The csv will have existing content and I only need to append data which will be added via my powershell script.
within the script I am creating new objects the following way
$newData = @{'Serial' = 10; 'Customer' = 'NewCustomerName'; 'Seat' = 100} $a = new-object -TypeName PsObject -Property $newData $a |export-data "c:\location\thecsv.csv" -append
I get an error:
Export-Csv : Cannot append CSV content to the following file: C:\test\PSTesting.csv. The
appended object does not have a property that corresponds to the following column:
Serial. To continue with mismatched properties, add the -Force parameter, and then retry
the command.
At line:1 char:5
- $a |Export-Csv C:\test\PSTesting.csv -Append
-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- CategoryInfo : InvalidData: (Serial:String) [Export-Csv], InvalidOperatio
nException - FullyQualifiedErrorId : CannotAppendCsvWithMismatchedPropertyNames,Microsoft.Power
Shell.Commands.ExportCsvCommand
- CategoryInfo : InvalidData: (Serial:String) [Export-Csv], InvalidOperatio
I am sure that those properties exist AND that there is no typo.
What the problem seems to be is when I do a get-member against the $a its not showing any of those three properties.
It will display them when I just type $a but it will ‘Serial’, ‘Customer’, or ‘Seat’ as a property in GM.
Any thoughts on how to create the object so that the properties are part of it?
This me prototyping to see if I can use PS at scale with a living csv file (I know pretty bad). And not being able to figure out why new objects aren’t listing properties in GM is driving me crazy.