Create objects from CSV variable-length strings that are generated by ConvertTo-CSV.

      ConvertFrom-CSV [[-Delimiter] char]
         [-InputObject] PSObject[] [-Header string[]] [CommonParameters]
      ConvertFrom-CSV -UseCulture
         [-InputObject] PSObject[] [-Header string[]] [CommonParameters]

   -Delimiter char
       The delimiter to separate property values. Default = comma (,).
       Enter a character, such as a colon (:). 

       To specify a semicolon (;), enclose it in quotation marks.
       Otherwise, it will be interpreted as the command delimiter.

    -Header string[]
An alternate column header row for the imported string. This determines the property names of the object created.
Enter a comma-separated list, enclose each item in quotes (single or double). If you enter fewer column headers than there are columns, the
remaining columns will have no headers. If you enter too many headers, the extra headers are ignored.

When using -Header, omit the column headers from the CSV strings. Otherwise, ConvertFrom-CSV will create an extra object from the header row. -InputObject psobject The CSV strings to import as objects. Enter a variable that contains the CSV strings or type an expression that returns the CSV strings. You can also pipe the CSV strings to ConvertFrom-CSV. -UseCulture Use the list separator for the current culture as the data delimiter. Default = comma (,) This parameter is very useful in scripts that are being distributed to users worldwide. To find the list separator for a culture, use the following: (Get-Culture).TextInfo.ListSeparator. This must match the delimiter that's actually used in the CSV strings. CommonParameters: -Verbose, -Debug, -ErrorAction, -ErrorVariable, -WarningAction, -WarningVariable, -OutBuffer -OutVariable.

ConvertFrom-CSV creates objects from CSV variable-length strings that are generated by ConvertTo-CSV
The -header parameter allows you to specify the property names of the resulting objects.

The objects that ConvertFrom-CSV creates are CSV versions of the original objects. The property values of the CSV objects are string versions of the property values of the original objects. The CSV versions of the objects do not have any methods.

Import-CSV is the same as ConvertFrom-CSV, except that it reads from a file.


Convert a date object to CSV format, and then to CSV object format.:

C:\PS> $date = get-date | convertto-csv -delimiter ";"

C:\PS> convertfrom-csv -inputobject $date -delimiter ";"

Convert a process object to CSV format:

C:\PS> $p = get-process | convertto-csv

C:\PS> $p | convertfrom-csv

a) Start a background job that converts a process object to CSV format:
C:\PS> $job = start-job -scriptblock { get-process } | convertto-csv

b) Store the new header details in a variable:
C:\PS> $proc_header = "MoreData", "StatusMessage", "Location", "Command", "State", "Finished", "InstanceId", "SessionId", "Name" ,"ChildJobs", "Output", "Error", "Progress", "Verbose", "Debug", "Warning", "StateChanged"

c) Delete the original header details (the second line) from $job
C:\PS> $job = $job[0], $job[2..($job.count - 1)]

d) Convert the CSV strings to a CSV version of the job object with the new header details.
C:\PS> $job | convertfrom-csv -header $proc_header

“An honest tale speeds best being plainly told” - William Shakespeare


Export-Csv - Export to Comma Separated Values (spreadsheet)

Copyright © 1999-2017
Some rights reserved