ConvertFrom-OfficeCsv
Converts CSV text into PSCustomObjects, dictionaries, a DataTable, a data reader or a CsvDocument.
Syntax
ConvertFrom-OfficeCsv
[-AllowEmptyLines]
[-As <Object| Hashtable| DataTable| DataReader| Document>]
[-CollectParseErrors]
[-ColumnCountMismatchPolicy <Strict| PadMissingFieldsAndIgnoreExtraFields>]
[-ColumnType <IDictionary>]
[-CommentCharacter <Char>]
[-Culture <CultureInfo>]
[-DateTimeFormats <String[]>]
[-Delimiter <String>]
[-DuplicateHeaderBehavior <Preserve| Rename| Throw>]
[-EscapeCharacter <Char>]
[-Header <String[]>]
[-InferSchema]
[-InputObject] <String[]>
[-InternStrings]
[-MaxFieldLength <Int32>]
[-MaxParseErrors <Int32>]
[-MaxQuotedFieldLength <Int32>]
[-NoHeader]
[-NormalizeQuotes]
[-NoSkipCommentRowsBeforeHeader]
[-NoW3CFieldsHeader]
[-NullValue <String>]
[-ParseErrorAction <Throw| SkipRow>]
[-QuoteCharacter <Char>]
[-QuoteParsingMode <Lenient| Strict>]
[-SchemaSampleRows <Int32>]
[-SkipCommentRows]
[-SkipRows <Int32>]
[-StaticColumns <IDictionary>]
[-TrimWhitespace]
[<CommonParameters>]#InputObjectConvertFrom-OfficeCsv
[-AllowEmptyLines]
[-As <Object| Hashtable| DataTable| DataReader| Document>]
[-CollectParseErrors]
[-ColumnCountMismatchPolicy <Strict| PadMissingFieldsAndIgnoreExtraFields>]
[-ColumnType <IDictionary>]
[-CommentCharacter <Char>]
[-Culture <CultureInfo>]
[-DateTimeFormats <String[]>]
[-DelimiterCandidates <Char[]>]
-DetectDelimiter
[-DuplicateHeaderBehavior <Preserve| Rename| Throw>]
[-EscapeCharacter <Char>]
[-Header <String[]>]
[-InferSchema]
[-InputObject] <String[]>
[-InternStrings]
[-MaxFieldLength <Int32>]
[-MaxParseErrors <Int32>]
[-MaxQuotedFieldLength <Int32>]
[-NoHeader]
[-NormalizeQuotes]
[-NoSkipCommentRowsBeforeHeader]
[-NoW3CFieldsHeader]
[-NullValue <String>]
[-ParseErrorAction <Throw| SkipRow>]
[-QuoteCharacter <Char>]
[-QuoteParsingMode <Lenient| Strict>]
[-SchemaSampleRows <Int32>]
[-SkipCommentRows]
[-SkipRows <Int32>]
[-StaticColumns <IDictionary>]
[-TrimWhitespace]
[<CommonParameters>]#InputObjectDetectConvertFrom-OfficeCsv
[-AllowEmptyLines]
[-As <Object| Hashtable| DataTable| DataReader| Document>]
[-CollectParseErrors]
[-ColumnCountMismatchPolicy <Strict| PadMissingFieldsAndIgnoreExtraFields>]
[-ColumnType <IDictionary>]
[-CommentCharacter <Char>]
[-Culture <CultureInfo>]
[-DateTimeFormats <String[]>]
[-DuplicateHeaderBehavior <Preserve| Rename| Throw>]
[-EscapeCharacter <Char>]
[-Header <String[]>]
[-InferSchema]
[-InputObject] <String[]>
[-InternStrings]
[-MaxFieldLength <Int32>]
[-MaxParseErrors <Int32>]
[-MaxQuotedFieldLength <Int32>]
[-NoHeader]
[-NormalizeQuotes]
[-NoSkipCommentRowsBeforeHeader]
[-NoW3CFieldsHeader]
[-NullValue <String>]
[-ParseErrorAction <Throw| SkipRow>]
[-QuoteCharacter <Char>]
[-QuoteParsingMode <Lenient| Strict>]
[-SchemaSampleRows <Int32>]
[-SkipCommentRows]
[-SkipRows <Int32>]
[-StaticColumns <IDictionary>]
[-TrimWhitespace]
-UseCulture
[<CommonParameters>]#InputObjectCultureDescription
The reverse of ConvertTo-OfficeCsv and the text form of Import-OfficeCsv: piped strings are read as lines of one CSV text, as ConvertFrom-Csv reads them, and parsed with Import-OfficeCsv's options and output shapes. Use Import-OfficeCsv when the source is a file.
Examples
Read CSV text as objects.
"Name,Total`nAlpha,10`nBeta,7" | ConvertFrom-OfficeCsvEmits one PSCustomObject per row, with property names from the header.
Round-trip objects through CSV text.
$rows = Get-Process | Select-Object -First 5 Name, Id | ConvertTo-OfficeCsv | ConvertFrom-OfficeCsvReads the text ConvertTo-OfficeCsv writes back into objects.
Read semicolon-separated lines as a typed DataTable.
Get-Content ./export.txt | ConvertFrom-OfficeCsv -Delimiter ';' -As DataTable -InferSchemaJoins the lines Get-Content emits and infers column types from the values.
Parameters
- -AllowEmptyLines SwitchParameter
- Allow empty lines in the input.
- -As OfficeCsvOutput
- Output shape: Object, Hashtable, DataTable, DataReader or Document.
- Possible values:
Object,Hashtable,DataTable,DataReader,Document - -CollectParseErrors SwitchParameter
- Collect parse errors and write them as non-terminating errors after the rows.
- -ColumnCountMismatchPolicy CsvColumnCountMismatchPolicy
- Controls how rows with fewer or more fields than the header are handled.
- Possible values:
Strict,PadMissingFieldsAndIgnoreExtraFields - -ColumnType IDictionary
- Explicit column types used when emitting DataTable or IDataReader output.
- -CommentCharacter Char
- Character that identifies comment rows.
- -Culture CultureInfo
- Culture used for type conversions, and for the delimiter with UseCulture.
- -DateTimeFormats String[]
- Additional date/time formats used by typed conversions and validation.
- -Delimiter String
- Field delimiter, including multi-character delimiters.
- -DuplicateHeaderBehavior CsvDuplicateHeaderBehavior
- Controls how duplicate header names are handled.
- Possible values:
Preserve,Rename,Throw - -EscapeCharacter Char
- Character that escapes the quote character, or itself, inside quoted fields, such as a backslash. Leave unset to read a doubled quote character as one.
- -Header String[]
- Explicit header names to use; when provided, the first CSV record is treated as data.
- -InferSchema SwitchParameter
- Infer typed columns when -As DataTable or -As DataReader is used.
- -InputObject String[]
- CSV text, as one string or as lines; piped strings are joined with line breaks.
- -InternStrings SwitchParameter
- Reuse repeated string values through a per-read cache.
- -MaxFieldLength Int32
- Maximum length allowed for any parsed field.
- -MaxParseErrors Int32
- Maximum number of collected parse errors before parsing fails.
- -MaxQuotedFieldLength Int32
- Maximum length allowed for fields parsed from quoted records.
- -NoHeader SwitchParameter
- Treat the first record as data and generate default column names.
- -NormalizeQuotes SwitchParameter
- Normalize curly quote characters to straight quotes.
- -NoSkipCommentRowsBeforeHeader SwitchParameter
- Keep comment rows while discovering the header.
- -NoW3CFieldsHeader SwitchParameter
- Disable W3C Extended Log File Format #Fields: headers.
- -NullValue String
- Token that is materialized as null.
- -ParseErrorAction CsvParseErrorAction
- How parse errors are handled.
- Possible values:
Throw,SkipRow - -QuoteCharacter Char
- Character that encloses quoted fields. Defaults to the double quote.
- -QuoteParsingMode CsvQuoteParsingMode
- Controls whether malformed quoted fields are parsed leniently or rejected.
- Possible values:
Lenient,Strict - -SchemaSampleRows Int32
- Maximum row count inspected when schema inference is enabled.
- -SkipCommentRows SwitchParameter
- Skip comment rows throughout the text.
- -SkipRows Int32
- Number of parsed CSV records to skip before header discovery or data output.
- -StaticColumns IDictionary
- Static columns appended to every row.
- -TrimWhitespace SwitchParameter
- Trim whitespace around unquoted fields.
- -DelimiterCandidates Char[]
- Delimiter candidates to consider when detecting the delimiter.
- -DetectDelimiter SwitchParameter
- Detect the delimiter from the first meaningful records.
- -UseCulture SwitchParameter
- Use the list separator from the selected or current culture as the delimiter.
Common Parameters
This command supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable.
For more information, see about_CommonParameters.