I have a process parsing out a number of CSV documents and saving changes for later processing in a database. When one row (a person) in any of the CSVs isn't found in the person database, the process saves off that record from the CSV. I currently have it saving as the string output of the hashtable. So CSV document
First,Last,Office
Joe,Smith,Detroit
The output from import-csv "path to my doc.csv"
when using the debugger in VS 2015 the string is visualized as:
@{First=Joe; Last=Smith; Office=Detroit;}
It also expands out to be a key/value set of:
First | Joe
Last | Smith
Office | Detroit
In powershell, I'm able to just use the names objects in the table as $obj.First
and move on with things. But I'm not able to save that string to a database, and bring it back as a usable powershell object. I always end up with the string literal.
Is there a way to convert this string back to a hashtable, or other key/value pair?
I've given this a try:
$data = ConvertFrom-String $raw -PropertyNames First,Last,Office
I've tried that on both the raw string as is, which just gives the string back, with the property names in it. I've also converted the original hash to an array:
[string[]]$l_array = $raw | out-string
Then when I convert it back using the ConvertFrom-String
command, it is actually shifting the data elements and adding the keys, as values.
Thanks for the help. I can provide more details, or sample code as needed.
Edit The other side of this, is, how could I store the data that is currently a PSCustomObject, in a better format, that I can rebuild into the same PSCustomObject? I thought perhaps Export-Csv might work, but you can't export to a string. At least as far as I can tell.
Import-Csv
produces an array of PSCustomObjects not a hash table. Can you explain what "when looking" means? How are you viewing the result? - Dave SextonPSCustomObjects
create utilized the same as a hashtable? I'll update the post to clarify. - Tim Meers