Convert CSV string to PS Object in PowerShell

You might have used the powershell command Import-Csv to import content from csv file. Sometimes we may required to convert csv (comma-separated-values) string content to object, we can easily achieve this using the cmdlet ConvertFrom-Csv.

$csv_content = "col1,col2`
val11,val12`
val21,val22"

$ps_object = $csv_content | ConvertFrom-Csv -Delim ','

Powershell Object:

PS C:> $ps_object

col1  col2
----  ----
val11 val12
val21 val22

Advertisement

Leave a Comment