PowerShell Logo Small

ConvertFrom-Csv



This is the built-in help made by Microsoft for the command 'ConvertFrom-Csv', in PowerShell version 5 - as retrieved from Windows version 'Microsoft Windows Server 2012 R2 Standard' PowerShell help files on 2016-06-23.

For PowerShell version 3 and up, where you have Update-Help, this command was run just before creating the web pages from the help files.

SYNOPSIS

Converts object properties in comma-separated value (CSV) format into CSV versions of the original objects.

SYNTAX


ConvertFrom-Csv [-InputObject] <PSObject[]> [[-Delimiter] [<Char>]] [-Header [<String[]>]] [-InformationAction {SilentlyContinue | Stop | Continue | Inquire | Ignore |
Suspend}] [-InformationVariable [<System.String>]] [<CommonParameters>]
ConvertFrom-Csv [-InputObject] <PSObject[]> [-Header [<String[]>]] [-InformationAction {SilentlyContinue | Stop | Continue | Inquire | Ignore | Suspend}]
[-InformationVariable [<System.String>]] -UseCulture [<CommonParameters>]



Search powershellhelp.space

DESCRIPTION


The ConvertFrom-CSV cmdlet creates objects from CSV variable-length strings that are generated by the ConvertTo-CSV cmdlet.


You can use the parameters of the ConvertFrom-CSV cmdlet to specify the column header row, which determines the property names of the resulting objects, to specify the item
delimiter, or to direct ConvertFrom-CSV to use the list separator for the current culture as the delimiter.


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.


You can also use the Export-CSV and Import-CSV cmdlets to convert objects to CSV strings in a file (and back). These cmdlets are the same as the ConvertTo-CSV and
ConvertFrom-CSV cmdlets, except that they save the CSV strings in a file.



<

RELATED LINKS

Online Version: http://go.microsoft.com/fwlink/p/?linkid=293946
ConvertTo-Csv
Export-Csv
Import-Csv

REMARKS

<

Examples


-------------------------- EXAMPLE 1 --------------------------

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



These commands convert the processes on the local computer into CSV format and then restore them to object form.

The first command uses the Get-Process cmdlet to get the processes on the local computer. A pipeline operator (|) sends them to the ConvertTo-CSV cmdlet, which converts the
process object to CSV format. The CSV strings are saved in the $p variable.

The second command uses a pipeline operator to send the CSV strings in the $p variable to the ConvertFrom-CSV cmdlet. The cmdlet converts the CSV strings into CSV versions
of the original process objects.










-------------------------- EXAMPLE 2 --------------------------

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



These commands convert a data object to CSV format and then to CSV object format.

The first command uses the Get-Date cmdlet to get the current date and time. A pipeline object (|) sends the date to the ConvertTo-CSV cmdlets, which converts the date
object to a series of CSV strings. The command uses the Delimiter parameter to specify a semicolon delimiter. The strings are saved in the $date variable.

The second command uses the ConvertFrom-CSV cmdlet to convert the CSV strings in the $date variable back to object format. The command uses the InputObject parameter to
specify the CSV strings and the Delimiter parameter to specify the semicolon delimiter.










-------------------------- EXAMPLE 3 --------------------------

PS C:\>$j = start-job -scriptblock { get-process } | convertto-csv
PS C:\>$header = "MoreData","StatusMessage","Location","Command","State","Finished","InstanceId","SessionId","Name","ChildJobs","Output","Error","Progress","Verbose","Debug",
"Warning","StateChanged"
# Delete header from $j
PS C:\>$j = $j[0], $j[2..($j.count - 1)]
$j | convertfrom-csv -header $header

MoreData : True
StatusMessage :
Location : localhost
Command : get-process
State : Running
Finished : System.Threading.ManualResetEvent
InstanceId : 6fcb6578-7f42-4d93-9f23-9937f6aac1a2
SessionId : 1
Name : Job1
ChildJobs : System.Collections.Generic.List`1[System.Management.Automation.Job]
Output : System.Management.Automation.PSDataCollection`1[System.Management.Automation.PSObject]
Error : System.Management.Automation.PSDataCollection`1[System.Management.Automation.ErrorRecord]
Progress : System.Management.Automation.PSDataCollection`1[System.Management.Automation.ProgressRecord]
Verbose : System.Management.Automation.PSDataCollection`1[System.String]
Debug : System.Management.Automation.PSDataCollection`1[System.String]
Warning : System.Management.Automation.PSDataCollection`1[System.String]
StateChanged :



This example shows how to use the Header parameter of ConvertFrom-Csv to change the names of properties in the resulting imported object.

The first command uses the Start-Job cmdlet to start a background job that runs a Get-Process command on the local computer. A pipeline operator (|) sends the resulting job
object to the ConvertTo-CSV cmdlet, which converts the job object to CSV format. An assignment operator (=) saves the resulting CSV in the $j variable.

The second command saves a header in the $header variable. Unlike the default header, this header uses "MoreData" instead of "HasMoreData" and "State" instead of
"JobStateInfo".

The third command deletes the original header (the second line) from the CSV strings and returns it to the $j variable.

The fourth command uses the ConvertFrom-CSV cmdlet to convert the CSV strings to a CSV version of the job object. The command uses a pipeline operator to send the content in
$j to ConvertFrom-CSV. The resulting object has "MoreData" and "State" properties, as specified by the header.










-------------------------- EXAMPLE 4 --------------------------

PS C:\>(get-culture).textinfo.listseparator
PS C:\>ConvertFrom-Csv -inputobject $services -UseCulture



The command uses the ConvertFrom-CSV cmdlet to convert CSV strings of service objects that had been converted by the ConvertTo-CSV cmdlet. The command uses the UseCulture
parameter to direct ConvertFrom-CSV to use the delimiter (list separator) of the current culture.

When using the UseCulture parameter, be sure that the list separator of the current culture matches the delimiter used in the CSV strings. Otherwise, ConvertFrom-CSV cannot
generate objects from the CSV strings.

In this example, a Get-Culture command was used to verify the list separator, before the ConvertFrom-CSV command was used.