API Reference
Cmdlet
ConvertTo-OfficeCsv
Converts objects or a CSV document into CSV text.
Remarks
Use Export-OfficeCsv when the destination is a file.
Examples
Example 1: Convert objects to CSV text.
PS>
$csv = $data | ConvertTo-OfficeCsv
Generates CSV text from the input objects.
Example 2: Export with a stable schema order.
PS>
$rows = @(
[ordered]@{ Id = 1; Name = 'Alpha'; Total = 10.5 },
[ordered]@{ Id = 2; Name = 'Beta'; Total = 7.25 }
)
$csv = $rows | ConvertTo-OfficeCsv -Delimiter ';'
Uses ordered dictionaries to enforce column order and a custom delimiter.
Example 3: Write CSV without headers.
PS>
$csv = $data | ConvertTo-OfficeCsv -NoHeader
Writes rows only when a downstream system expects headerless CSV.
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.
Syntax
ConvertTo-OfficeCsv [-Culture <CultureInfo>] [-DateTimeFormat <String>] [-Delimiter <Char>] [-DelimiterText <String>] [-FormulaInjectionPolicy <Preserve|Escape>] [-InputObject <Object>] [-NewLine <String>] [-NoHeader] [-NullValue <String>] [-QuoteFields <String[]>] [-UseQuotes <AsNeeded|Always|Never>] [-UseUtc] [<CommonParameters>]#Parameter set:
InputObjectDelimiterParameters
- Culture CultureInfo
- Culture used for value formatting.
- DateTimeFormat String
- Date/time format used for DateTime and DateTimeOffset values.
- Delimiter Char
- Field delimiter character.
- DelimiterText String
- Field delimiter text for multi-character delimiters such as || or ::.
- FormulaInjectionPolicy CsvFormulaInjectionPolicy
- Controls how formula-like values are written. Possible values: Preserve, Escape
- Possible values:
Preserve,Escape - InputObject Object
- Objects to convert into CSV rows.
- NewLine String
- Override the newline sequence.
- NoHeader SwitchParameter
- Omit the header row from the output.
- NullValue String
- Token written for null values.
- QuoteFields String[]
- Field names that should always be quoted when UseQuotes is AsNeeded.
- UseQuotes CsvQuoteMode
- Controls when CSV fields are quoted. Defaults to quoting only fields that need it. Possible values: AsNeeded, Always, Never
- Possible values:
AsNeeded,Always,Never - UseUtc SwitchParameter
- Convert date/time values to UTC before formatting.
Outputs
System.String
ConvertTo-OfficeCsv [-Culture <CultureInfo>] [-DateTimeFormat <String>] [-Delimiter <Char>] [-DelimiterText <String>] -Document <CsvDocument> [-FormulaInjectionPolicy <Preserve|Escape>] [-NewLine <String>] [-NoHeader] [-NullValue <String>] [-QuoteFields <String[]>] [-UseQuotes <AsNeeded|Always|Never>] [-UseUtc] [<CommonParameters>]#Parameter set:
DocumentDelimiterParameters
- Culture CultureInfo
- Culture used for value formatting.
- DateTimeFormat String
- Date/time format used for DateTime and DateTimeOffset values.
- Delimiter Char
- Field delimiter character.
- DelimiterText String
- Field delimiter text for multi-character delimiters such as || or ::.
- Document CsvDocument
- CSV document to serialize.
- FormulaInjectionPolicy CsvFormulaInjectionPolicy
- Controls how formula-like values are written. Possible values: Preserve, Escape
- Possible values:
Preserve,Escape - NewLine String
- Override the newline sequence.
- NoHeader SwitchParameter
- Omit the header row from the output.
- NullValue String
- Token written for null values.
- QuoteFields String[]
- Field names that should always be quoted when UseQuotes is AsNeeded.
- UseQuotes CsvQuoteMode
- Controls when CSV fields are quoted. Defaults to quoting only fields that need it. Possible values: AsNeeded, Always, Never
- Possible values:
AsNeeded,Always,Never - UseUtc SwitchParameter
- Convert date/time values to UTC before formatting.
Outputs
System.String
ConvertTo-OfficeCsv [-Culture <CultureInfo>] [-DateTimeFormat <String>] -Document <CsvDocument> [-FormulaInjectionPolicy <Preserve|Escape>] [-NewLine <String>] [-NoHeader] [-NullValue <String>] [-QuoteFields <String[]>] -UseCulture [-UseQuotes <AsNeeded|Always|Never>] [-UseUtc] [<CommonParameters>]#Parameter set:
DocumentCultureParameters
- Culture CultureInfo
- Culture used for value formatting.
- DateTimeFormat String
- Date/time format used for DateTime and DateTimeOffset values.
- Document CsvDocument
- CSV document to serialize.
- FormulaInjectionPolicy CsvFormulaInjectionPolicy
- Controls how formula-like values are written. Possible values: Preserve, Escape
- Possible values:
Preserve,Escape - NewLine String
- Override the newline sequence.
- NoHeader SwitchParameter
- Omit the header row from the output.
- NullValue String
- Token written for null values.
- QuoteFields String[]
- Field names that should always be quoted when UseQuotes is AsNeeded.
- UseCulture SwitchParameter
- Use the list separator from the selected or current culture as the delimiter.
- UseQuotes CsvQuoteMode
- Controls when CSV fields are quoted. Defaults to quoting only fields that need it. Possible values: AsNeeded, Always, Never
- Possible values:
AsNeeded,Always,Never - UseUtc SwitchParameter
- Convert date/time values to UTC before formatting.
Outputs
System.String
ConvertTo-OfficeCsv [-Culture <CultureInfo>] [-DateTimeFormat <String>] [-FormulaInjectionPolicy <Preserve|Escape>] [-InputObject <Object>] [-NewLine <String>] [-NoHeader] [-NullValue <String>] [-QuoteFields <String[]>] -UseCulture [-UseQuotes <AsNeeded|Always|Never>] [-UseUtc] [<CommonParameters>]#Parameter set:
InputObjectCultureParameters
- Culture CultureInfo
- Culture used for value formatting.
- DateTimeFormat String
- Date/time format used for DateTime and DateTimeOffset values.
- FormulaInjectionPolicy CsvFormulaInjectionPolicy
- Controls how formula-like values are written. Possible values: Preserve, Escape
- Possible values:
Preserve,Escape - InputObject Object
- Objects to convert into CSV rows.
- NewLine String
- Override the newline sequence.
- NoHeader SwitchParameter
- Omit the header row from the output.
- NullValue String
- Token written for null values.
- QuoteFields String[]
- Field names that should always be quoted when UseQuotes is AsNeeded.
- UseCulture SwitchParameter
- Use the list separator from the selected or current culture as the delimiter.
- UseQuotes CsvQuoteMode
- Controls when CSV fields are quoted. Defaults to quoting only fields that need it. Possible values: AsNeeded, Always, Never
- Possible values:
AsNeeded,Always,Never - UseUtc SwitchParameter
- Convert date/time values to UTC before formatting.
Outputs
System.String