Export-Csv

 

Additional Resources for Export-Csv

 

Saving Data as a Comma-Separated Values File

http://www.microsoft.com/technet/scriptcenter/topics/msh/cmdlets/export-csv.mspx

 

 

SYNOPSIS

Creates a comma-separated values (CSV) file that represents the input objects.

 

SYNTAX

Export-Csv [-path] <string> -inputObject <psobject> [-force] [-encoding <string>] [-noTypeInformation] [-noClobber] [-whatIf] [-confirm] [<CommonParameters>]

 

DETAILED DESCRIPTION

Creates a comma-separated values (CSV) file that represents the input objects.

 

Unless the NoTypeInformation parameter is specified, the first line of the CSV file contains the string '#TYPE ' followed by the fully-qualified name of the type being represented. For example: #TYPE System.Diagnostics.Process.

 

The next line of the CSV file represents column headers. It contains a comma-separated list of the names of all the properties of the first input object.

 

Additional lines of the file contain comma-separated lists of the values of each of the properties named in the column header line for each input object.

 

The first object establishes the column headers. The headers are not modified in response to subsequent input objects. If those objects do not include some of the properties in the column header line, no value is written for that property of that object. Instead, two commas are written to indicate a missing property and ensure proper alignment of property values with the property names in the column headers.

 

Property values that contain commas, double quotes,  leading or trailing spaces, or line breaks, are put in double quotes before being written to the CSV file. Any double quotes contained in a property are redoubled to indicate that they are literal.

 

You can use the Import-CSV cmdlet to use the information in the CSV file to recreate the input objects.

 

PARAMETERS

 

-path <string>

Specifies the path to the CSV to create.

 

Required?

true

Position?

1

Default value

Null

Accept pipeline input?   

false

Accept wildcard characters? 

true

 

-inputObject <psobject>

Accepts objects that the cmdlet will represents as a CSV file. Enter a variable that contains the objects or type a command or expression that gets the objects.

 

Required?

true

Position?

named

Default value

 

Accept pipeline input?  

true (ByValue)

Accept wildcard characters? 

false

 

-force <SwitchParameter>

Overwrites the file specified in path without prompting.

 

Required?

false

Position?

named

Default value

False

Accept pipeline input?  

false

Accept wildcard characters? 

false

 

-encoding <string>

Sets the type of encoding for the exported CSV file. Values can be: Unicode, UTF7, UTF8, ASCII.

 

Required?

false

Position?

named

Default value

ASCII

Accept pipeline input?  

false

Accept wildcard characters? 

false

 

-noTypeInformation <SwitchParameter>

Omits the #TYPE header from the CSV file. If this parameter is not specified, the first line of the CSV file contains the string "#TYPE " followed by the fully-qualified name of the type of the object. If this parameter is specified, no type information is included in the CSV file.

 

Required?

false

Position?

named

Default value

False

Accept pipeline input?  

false

Accept wildcard characters? 

false

 

-noClobber <SwitchParameter>

Will 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?

alse

Position?

named

Default value

False

Accept pipeline input?  

false

Accept wildcard characters? 

false

 

-whatIf

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

 

-confirm

Prompts you for confirmation before 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, and -OutVariable. For more information, type, "get-help about_commonparameters".

 

INPUT TYPE

Any object(s)

 

RETURN TYPE

CSV list

 

NOTES

 

The ToString method is called on each property of each input object to retrieve a string version of the value of the properties.

 

For more information, type "Get-Help Export-Csv -detailed". For technical information, type "Get-Help Export-Csv -full".

 

When specifying multiple values for a parameter, use commas to separate the values. For example, "<parameter-name> <value1>, <value2>".

 

EXAMPLE 1

 

get-process wmiprvse | select-object basePriority,ID,SessionID,WorkingSet | export-csv -path data.csv

 

This command selects a few properties of the wmiprvse process and exports them to a CSV format file named data.csv.

 

RELATED LINKS

Import-Csv

Export-Clixml

ConvertTo-Html