CmdID

CmdID / PowerShell / Cmdlets / Import

Import-Csv

Creates table-like custom objects from the items in a character-separated value (CSV) file. PowerShell reference

From the PowerShell reference 6 parameters Alias ipcsv

Opens CmdID with your command, read as PowerShell. It is read in your browser and sent nowhere.

What it does

from the PowerShell reference, CC BY 4.0

Creates table-like custom objects from the items in a character-separated value (CSV) file. The Import-Csv cmdlet creates table-like custom objects from the items in CSV files. Each column in the CSV file becomes a property of the custom object and the items in rows become the property values. Import-Csv works on any CSV file, including files that are generated by the Export-Csv cmdlet. You can use the parameters of the Import-Csv cmdlet to specify the column header row and the item delimiter, or direct Import-Csv to use the list separator for the current culture as the item delimiter. You can also use the ConvertTo-Csv and ConvertFrom-Csv cmdlets to convert objects to CSV strings (and back). These cmdlets are the same as the Export-Csv and Import-Csv cmdlets, except that they work with data from the pipeline instead of from files. If a header row entry in a CSV file contains an empty or null value, PowerShell inserts a default header row name and displays a warning message. Import-Csv uses the byte-order-mark (BOM) to detect the encoding format of the file. If the file has no BOM, it assumes the encoding is UTF8.

Import-Csv [[-Path] <string[]>] [[-Delimiter] <char>] [-LiteralPath <string[]>] [-Header <string[]>] [-Encoding <string>] [<CommonParameters>]
Import-Csv [[-Path] <string[]>] -UseCulture [-LiteralPath <string[]>] [-Header <string[]>] [-Encoding <string>] [<CommonParameters>]

Import process objects

Get-Process | Export-Csv -Path .\Processes.csv $P = Import-Csv -Path .\Processes.csv $P | Get-MemberIdentify

Specify the delimiter

Get-Process | Export-Csv -Path .\Processes.csv -Delimiter : $P = Import-Csv -Path .\Processes.csv -Delimiter : $P | Format-TableIdentify

Specify the current culture for the delimiter

(Get-Culture).TextInfo.ListSeparator Get-Process | Export-Csv -Path .\Processes.csv -UseCulture Import-Csv -Path .\Processes.csv -UseCultureIdentify

Change property names in an imported object

Start-Job -ScriptBlock { Get-Process } | Export-Csv -Path .\Jobs.csv -NoTypeInformation $Header = 'State', 'MoreData', 'StatusMessage', 'Location', 'Command', 'StateInfo', 'Finished', 'InstanceId', 'Id', 'Name', 'ChildJobs', 'BeginTime', 'EndTime', 'JobType', 'Output', 'Error', 'Progress', 'Verbose', 'Debug', 'Warning', 'Information' # Delete the default header from file $A = Get-Content -Path .\Jobs.csv $A = $A[1..($A.Count - 1)] $A | Out-File -FilePath .\Jobs.csv $J = Import-Csv -Path .\Jobs.csv -Header $Header $JIdentify

Create a custom object using a CSV file

Get-Content -Path .\Links.csvIdentify

Import a CSV that's missing a value

Get-Content -Path .\Projects.csvIdentify

Its page in the reference: Import-Csv.

Parameters

6 in the PowerShell reference
-DelimiterSpecifies the delimiter that separates the property values in the CSV file. The default is a comma (,). Enter a character, such as a colon (:). To specify a semicolon (;), enclose it in single quotation marks. To specify escaped special characters such as tab ( t ), enclose it in double quotation marks. If the specified character doesn't match the actual delimiter in the CSV data, Import-Csv can't parse each column into distinct properties. In this case, it outputs one PSCustomObject per row, each containing a single property whose name is the full header and whose value is the row text.
-EncodingSpecifies the type of encoding for the target file. The default value is Default. The acceptable values for this parameter are as follows: - ASCII Uses ASCII (7-bit) character set. - BigEndianUnicode Uses UTF-16 with the big-endian byte order. - Default Uses the encoding that corresponds to the system's active code page (usually ANSI). - OEM Uses the encoding that corresponds to the system's current OEM code page. - Unicode Uses UTF-16 with the little-endian byte order. - UTF7 Uses UTF-7. - UTF8 Uses UTF-8. - UTF32 Uses UTF-32 with the little-endian byte order.
-HeaderSpecifies an alternate column header row for the imported file. The column header determines the property names of the objects created by Import-Csv. Enter column headers as a character-separated list. Don't enclose the header string in quotation marks. Enclose each column header in single quotation marks. If you enter fewer column headers than there are data columns, the remaining data columns are discarded. If you enter more column headers than there are data columns, the additional column headers are created with empty data columns. When using the Header parameter, delete the original header row from the CSV file. Otherwise, Import-Csv creates an extra object from the items in the header row.
-LiteralPathSpecifies the path to the CSV file to import. Unlike Path, the value of the LiteralPath parameter is used exactly as it's typed. No characters are interpreted as wildcards. If the path includes escape characters, enclose it in single quotation marks. Single quotation marks tell PowerShell not to interpret any characters as escape sequences.
-PathSpecifies the path to the CSV file to import. You can also pipe a path to Import-Csv.
-UseCultureUses the list separator for the current culture as the item delimiter. To find the list separator for a culture, use the following command: (Get-Culture).TextInfo.ListSeparator.