< Back

Import-Csv2

Wed Jan 15, 2020 12:08 am

NAME Import-Csv2



SYNOPSIS

Import a CSV file.





SYNTAX

Import-Csv2 [[-Path] <String>] [[-Encoding] <Encoding>] [[-QuoteChar] <Char>] [[-TrimOption] {None | Trim |

InsideQuotes}] [[-InitialCapacity] <Int32>] [[-ColumnNames] <String[]>] [[-Strict]] [[-RecordType] <Type>]

[[-AsDictionary]] [[-AsDataTable]] [[-ColumnTypes] <IDictionary>] [[-AllowComments]] [[-BufferSize] <Int32>]

[[-CommentChar] <Char>] [[-Delimiter] <String>] [[-EscapeChar] <Char>] [[-KeepBlankLines]] [[-IgnoreQuote]]

[-NoHeaderRecord] [-ColumnNameMap <IDictionary>] [-Culture <CultureInfo>] [-Configuration <Configuration>]

[-InputObject <String>] [<CommonParameters>]





DESCRIPTION

This cmdlet reads a file or a pipeline stream, parses its content as the CSV format and returns the resultant

objects in several formats.



Compared to the built-in `Import-Csv` cmdlet, this cmdlet provides greater flexibility in parsing and supports

efficient object formats.



This cmdlet is built on top of CsvHelper, the well-known .NET library for reading or writing CSV files.





PARAMETERS

-AllowComments [<SwitchParameter>]

Sets a value indicating if comments are allowed. True to allow commented out lines, otherwise false.



This parameter corresponds to `CsvHelper.Configuration.Configuration.AllowComments`.



Required? false

Position? 2

Default value False

Accept pipeline input? False

Accept wildcard characters? false



-AsDataTable [<SwitchParameter>]

Indicates to produce an output as a `DataTable` object.



Required? false

Position? 17

Default value False

Accept pipeline input? False

Accept wildcard characters? false



-AsDictionary [<SwitchParameter>]

Indicates to produce an output as a `OrderedDictionary` object.



Required? false

Position? 16

Default value False

Accept pipeline input? False

Accept wildcard characters? false



-BufferSize <Int32>

Sets the size of the buffer used for reading CSV files. Default is 2048.



This parameter corresponds to `CsvHelper.Configuration.Configuration.BufferSize`.



Required? false

Position? 3

Default value None

Accept pipeline input? False

Accept wildcard characters? false



-ColumnNames <String[]>

Specifies new column names.



This parameter will be ignored when the `-RecordType` or `-AsDataTable` parameter is specified.



Required? false

Position? 13

Default value None

Accept pipeline input? False

Accept wildcard characters? false



-ColumnTypes <IDictionary>

Specifies the types of columns. It should be a dictionary of a column name and its type.



This parameter will be ignored when the `-RecordType` parameter is specified.



Required? false

Position? 18

Default value None

Accept pipeline input? False

Accept wildcard characters? false



-CommentChar <Char>

Sets the character used to denote a line that is commented out. Default is '#'.



This parameter corresponds to `CsvHelper.Configuration.Configuration.Comment`.



Required? false

Position? 4

Default value None

Accept pipeline input? False

Accept wildcard characters? false



-Delimiter <String>

Sets the delimiter used to separate fields. Default is `CultureInfo.TextInfo.ListSeparator`.



This parameter corresponds to `CsvHelper.Configuration.Configuration.Delimiter`.



Required? false

Position? 5

Default value None

Accept pipeline input? False

Accept wildcard characters? false



-Encoding <Encoding>

Specifies the text encoding of the input file.



Required? false

Position? 1

Default value None

Accept pipeline input? False

Accept wildcard characters? false



-EscapeChar <Char>

Sets the escape character used to escape a quote inside a field. Default is '"'.



This parameter corresponds to `CsvHelper.Configuration.Configuration.Escape`.



Required? false

Position? 6

Default value None

Accept pipeline input? False

Accept wildcard characters? false



-IgnoreQuote [<SwitchParameter>]

Sets a value indicating if quotes should be ignored when parsing and treated like any other character.



This parameter corresponds to `CsvHelper.Configuration.Configuration.IgnoreQuote`.



Required? false

Position? 9

Default value False

Accept pipeline input? False

Accept wildcard characters? false



-InitialCapacity <Int32>

Specifies the initial capacity of the List object that is created when the `-AsDictionary` parameter is set.



This parameter is effective in combination with hte `-AsDictionary` parameter.



Required? false

Position? 12

Default value None

Accept pipeline input? False

Accept wildcard characters? false



-KeepBlankLines [<SwitchParameter>]

Sets a value indicating if blank lines should be ignored when reading. True to ignore, otherwise false.

Default is false.



This parameter corresponds to `CsvHelper.Configuration.Configuration.IgnoreBlankLines`, but its meaning is

opposite.



Required? false

Position? 8

Default value False

Accept pipeline input? False

Accept wildcard characters? false



-Path <String>

Indicates the input CSV file.



Required? false

Position? 0

Default value None

Accept pipeline input? False

Accept wildcard characters? false



-QuoteChar <Char>

Sets the character used to quote fields. Default is '"'.



This parameter corresponds to `CsvHelper.Configuration.Configuration.Quote`.



Required? false

Position? 10

Default value None

Accept pipeline input? False

Accept wildcard characters? false



-RecordType <Type>

Indicates the record type into which the record will be mapped.



Required? false

Position? 15

Default value None

Accept pipeline input? False

Accept wildcard characters? false



-Strict [<SwitchParameter>]

Indicates to raise an error when the number of fields is different from that of the header record.



This parameter will be ignored when the `-RecordType` or `-AsDataTable` parameter is specified.



Required? false

Position? 14

Default value False

Accept pipeline input? False

Accept wildcard characters? false



-TrimOption <TrimOptions>

Sets the field trimming options. Default is `Trim`.



Required? false

Position? 11

Default value None

Accept pipeline input? False

Accept wildcard characters? false



-NoHeaderRecord [<SwitchParameter>]

Sets a value indicating if the CSV file has a header record. Default is false.



This parameter corresponds to `CsvHelper.Configuration.Configuration.HasHeaderRecord`, but its meaning is

opposite.



Required? false

Position? named

Default value False

Accept pipeline input? False

Accept wildcard characters? false



-ColumnNameMap <IDictionary>

Specifies the mapping from the field names or field indexes in the input file to the field names in the output

object.



With the `-RecordType` parameter, this parameter represents the mapping from the field names or field indexes

in the input file to the class field or property names.



Required? false

Position? named

Default value None

Accept pipeline input? False

Accept wildcard characters? false



-Culture <CultureInfo>

Specifies the culture that is used when type conversion is performed.



This parameter corresponds to `CsvHelper.Configuration.Configuration.CultureInfo`.



Required? false

Position? named

Default value None

Accept pipeline input? False

Accept wildcard characters? false



-Configuration <Configuration>

Specifies a `CsvHelper.Configuration.Configuration` object.



Required? false

Position? named

Default value None

Accept pipeline input? False

Accept wildcard characters? false



-InputObject <String>

Specifies the CSV strings to be converted to objects.



Required? false

Position? named

Default value None

Accept pipeline input? True (ByValue)

Accept wildcard characters? false



<CommonParameters>

This cmdlet supports the common parameters: Verbose, Debug,

ErrorAction, ErrorVariable, WarningAction, WarningVariable,

OutBuffer, PipelineVariable, and OutVariable. For more information, see

about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).



INPUTS

System.String







OUTPUTS

System.Data.DataTable,





System.Collections.Specialized.OrderedDictionary





System.Object







NOTES











RELATED LINKS

Online Version: https://github.com/horker/pscsvhelper/b ... rt-Csv2.md

CsvHelper https://joshclose.github.io/CsvHelper