Importing, exporting, and converting
Getting data in and out of PowerShell is a critical part of using the language. There are several commands dedicated to this task, including:
Export-Csv
Import-Csv
Export-CliXml
andImport-CliXml
Tee-Object
Other PowerShell modules, such as the ImportExcel
module, available in the PowerShell Gallery can be used to extend the output formats available. Commands such as ConvertTo-Html
, ConvertTo-Json
, and ConvertFrom-Json
are explored in later chapters.
The Export-Csv command
The Export-Csv
command writes data from objects to a text file, for example:
Get-Process | Export-Csv processes.csv
By default, Export-Csv
writes a comma-delimited file using UTF8 encoding and completely overwrites any file using the same name.
Export-Csv
may be used to add lines to an existing file using the Append
parameter. When the Append
parameter is used, the input object must have each of the fields listed in the...