Convert .NET Framework objects into Comma-Separated Value (CSV) variable-length strings.

      ConvertTo-CSV [[-Delimiter] char]
         [-InputObject] psobject [-IncludeTypeInformation] [-NoTypeInformation]
            [-QuoteFields String[]] [-UseQuotes QuoteKind] [CommonParameters]

      ConvertTo-CSV [-UseCulture]
         [-InputObject] psobject [-IncludeTypeInformation] [-NoTypeInformation]
            [-QuoteFields String[]] [-UseQuotes QuoteKind] [CommonParameters]

   -Delimiter char
       The delimiter to separate property values. Default = comma (,).
       Enter a character, such as a colon (:). 

       To specify a semicolon (;), enclose it in quotation marks. Otherwise, it
       will be interpreted as the command delimiter.

   -InputObject psobject
       The object(s) to export as CSV strings. Enter a variable that contains the
       object(s) or type an expression that returns the object(s).

       When the -InputObject parameter is used to submit a collection of items,
       ConvertTo-Csv receives one object that represents the collection.
       Because one object cannot be converted, ConvertTo-Csv returns the entire collection unchanged.

       To convert multiple items, pipe them to ConvertTo-Csv.

       This parameter is an implementation detail: its purpose is to enable input via the pipeline, and its
       direct use with arrays (collections) does not (yet) provide any useful functionality.

       When this parameter is used the first line of the output contains #TYPE followed by the
       fully qualified name of the object type. For example, #TYPE System.Diagnostics.Process.
       This parameter was introduced in PowerShell 6.0.

       Remove the #TYPE information header from the output. 
       This parameter became the default in PowerShell 6.0 and is included for backwards compatibility.

       Specifies the names of the columns that should be quoted.
       When this parameter is used only the specified columns are quoted. This parameter was added in PowerShell 7.0.

       Use the list separator for the current culture as the data delimiter. 
       Default = comma (,)

       This parameter is very useful in scripts that are being distributed to
       users worldwide. To find the list separator for a culture, use the following:

       Specifies when quotes are used in the CSV files.
       Possible values are:
          Never - don’t quote anything
          Always - quote everything (default behavior)
          AsNeeded - only quote fields that contain a delimiter character
       This parameter was added in PowerShell 7.0.

ConvertTo-CSV returns a series of comma-separated, variable-length (CSV) strings that represents the objects that you submit.
You can then use ConvertFrom-CSV to re-create objects from the CSV strings.

Export-CSV is the same as ConvertTo-CSV, except that it saves to a file.


Convert a date object to CSV format:

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

Convert a process object to CSV format:

PS C:\> get-process powershell | convertto-csv

Convert an event log object to CSV format:

PS C:\> get-eventlog -log "application" | convertto-csv -useculture

“Drunk with power isn’t the same as being drunk with booze” - Craig Ferguson

Related PowerShell Cmdlets

Export-Csv - Export to Comma Separated Values (spreadsheet)

Copyright © 1999-2023
Some rights reserved