NAME
Export-Csv
SYNOPSIS
Converts Microsoft .NET Framework objects into a series of comma-separated value (CSV) Variable-length strings and saves the strings in a CSV file.
SYNTAX
Export-Csv [[-Delimiter] <char>] [-Path] <string> -InputObject <psobject> [-Encoding <string>] [-Force] [-NoClobber] [-NoTypeInformation] [-Confirm] [-WhatIf] [<CommonParameters>]
Export-Csv [-UseCulture] [-Path] <string> -InputObject <psobject> [-Encoding <string>] [-Force] [-NoClobber] [-NoTypeInformation] [-Confirm] [-WhatIf] [<CommonParameters>]
DESCRIPTION
The Export-Csv cmdlet creates a CSV Variable-length file that represents the objects that you submit.
You can then use the Import-Csv cmdlet to re-create objects from the CSV strings in the files. The resulting objects are CSV versions of the original objects that consist of string representations of the property values and no methods.
You can also use the ConvertTo-Csv and ConvertFrom-Csv cmdlets to convert .NET Framework objects to CSV strings (and back). Export-Csv is the same as ConvertTo-Csv, except that it saves the CSV strings in a file.
You can use the parameters of the Export-Csv cmdlet to specify a delimiter other than a comma or to direct Export-Csv to use the default delimiter for the current culture.
When you submit multiple objects to Export-Csv, Export-Csv organizes the file based on the properties of the first object that you submit. If the remaining objects do not have one of the specified properties, the property value of that object is null, as represented by two consecutive commas. If the remaining objects have additional properties, those property values are not included in the file.
For more information, see Export-Csv, and see the Notes section.
PARAMETERS
-Delimiter <char>
Specifies a delimiter to separate the property values. The default is a comma (,). Enter a character, such as a colon (:). To specify a semicolon (;), enclose it in quotation marks.
Required? false
Position? 2
Default value , (comma)
Accept pipeline input? false
Accept wildcard characters? false
-Encoding <string>
Specifies the encoding for the exported CSV file. Valid values are Unicode, UTF7, UTF8, ASCII, UTF32, BigEndianUnicode, Default, and OEM. The default is ASCII.
Required? false
Position? named
Default value ASCII
Accept pipeline input? false
Accept wildcard characters? false
-Force [<SwitchParameter>]
Overwrites the file specified in path without prompting.
Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false
-InputObject <psobject>
Specifies the objects to export as CSV strings. Enter a Variable that contains the objects or type a command or expression that gets the objects. You can also pipe objects to Export-Csv.
Required? true
Position? named
Default value
Accept pipeline input? true (ByValue, ByPropertyName)
Accept wildcard characters? false
-NoClobber [<SwitchParameter>]
Do not overwrite (replace the contents) of an existing file. By default, if a file exists in the specified path, Export-Csv overwrites the file without warning.
Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false
-NoTypeInformation [<SwitchParameter>]
Omits the type information from the CSV file. By default, the first line of the CSV file contains “#TYPE ” followed by the fully-qualified name of the type of the .NET Framework object.
Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false
-Path <string>
Specifies the path to the CSV output file. The parameter is required.
Required? true
Position? 1
Default value
Accept pipeline input? false
Accept wildcard characters? false
-UseCulture [<SwitchParameter>]
Use the list separator for the current culture as the item delimiter. The default is a 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 command: (Get-Culture).TextInfo.ListSeparator.
Required? false
Position? named
Default value Comma
Accept pipeline input? false
Accept wildcard characters? false
-Confirm [<SwitchParameter>]
Prompts you for confirmation before executing the command.
Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false
-WhatIf [<SwitchParameter>]
Describes what would happen if you executed the command without actually executing the command.
Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false
<CommonParameters>
This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer and OutVariable. For more information, type,
“Get-Help about_CommonParameters“.
INPUTS
System.Management.Automation.PSObject
You can pipe any .NET Framework object to Export-Csv.
OUTPUTS
System.String
The CSV list is sent to the file designated in the Path parameter.
NOTES
The Export-Csv cmdlet converts the objects that you submit into a series of CSV Variable-length strings and saves them in the specified text file. You can use Export-Csv to save objects in a CSV file and then use the Import-Csv cmdlet to create objects from the text in the CSV file.
In the CSV file, each object is represented by a comma-separated list of the property values of the object. The property values are converted to strings (by using the ToString() method of the object), so they are generally represented by the name of the property value. Export-Csv does not export the methods of the object.
The format of an exported file is as follows:
— The first line of the CSV file contains the string ‘#TYPE ‘ followed by the fully qualified name of the .NET Framework type of the object, such as #TYPE System.Diagnostics.Process. To suppress this line, use the NoTypeInformation parameter.
— The next line of the CSV file represents the column headers. It contains a comma-separated list of the names of all the properties of the first object.
— Additional lines of the file consist of comma-separated lists of the property values of each object.
————————– EXAMPLE 1 ————————–
C:\PS>Get-Process wmiprvse | Select-Object basePriority,ID,SessionID,WorkingSet | Export-Csv -Path data.csv
Description
———–
This command selects a few properties of the wmiprvse process and exports them to a CSV format file named data.csv.
————————– EXAMPLE 2 ————————–
C:\PS>Get-Process | Export-Csv processes.csv
C:\PS> Get-Process | Export-Csv processes.csv
# In processes.csv
#TYPE System.Diagnostics.Process
__NounName,Name,Handles,VM,WS,PM,NPM,Path,Company,CPU,FileVersion,…
Process,powershell,626,201666560,76058624,61943808,11960,C:\WINDOWS…
Process,powershell,257,151920640,38322176,37052416,7836,C:\WINDOWS\…
Description
———–
This command exports objects representing the processes on the computer to the Processes.csv file in the current directory. Because it does not specify a delimiter, a comma (,) is used to separate the fields in the file.
————————– EXAMPLE 3 ————————–
C:\PS>Get-Process | Export-Csv processes.csv -Delimiter “;”
# In processes.csv
#TYPE System.Diagnostics.Process
__NounName;Name;Handles;VM;WS;PM;NPM;Path;Company;CPU;FileVersion;…
Process;powershell;626;201666560;76058624;61943808;11960;C:\WINDOWS…
Process;powershell;257;151920640;38322176;37052416;7836;C:\WINDOWS\…
Description
———–
This command exports objects representing the processes on the computer to the Processes.csv file in the current directory. It uses the Delimiter parameter to specify the semicolon (;). As a result, the fields in the file are separated by semicolons.
————————– EXAMPLE 4 ————————–
C:\PS>Get-Process | Export-Csv processes.csv -UseCulture
Description
———–
This command exports objects representing the processes on the computer to the Processes.csv file in the current directory. It uses the UseCulture parameter to direct Export-Csv to use the delimiter specified by the ListSeparator property of the current culture.
————————– EXAMPLE 5 ————————–
C:\PS>Get-Process | Export-Csv processes.csv -NoTypeInformation
C:\PS> Get-Process | Export-Csv processes.csv -NoTypeInformation
# In processes.csv
__NounName,Name,Handles,VM,WS,PM,NPM,Path,Company,CPU,FileVersion,…
Process,powershell,626,201666560,76058624,61943808,11960,C:\WINDOWS…
Process,powershell,257,151920640,38322176,37052416,7836,C:\WINDOWS\…
Description
———–
This command exports objects representing the processes on the computer to the Processes.csv file in the current directory. It uses the NoTypeInformation parameter to suppress the type information in the file.
RELATED LINKS
Online version: http://go.microsoft.com/fwlink/?LinkID=113299
Import-Csv
ConvertTo-Csv
ConvertFrom-Csv