Exporting to CSV and XML
In this recipe, we pipe the results of the Get-Process
cmdlet to a CSV and XML file.
How to do it...
Following are the steps to export to CSV and XML:
Open PowerShell ISE. Go to Start | Accessories | Windows PowerShell | Windows PowerShell ISE.
Add the following script and run it:
$csvFile = "C:\Temp\sample.csv" Get-Process | Export-Csv -path $csvFile -Force -NoTypeInformation notepad $csvFile $xmlFile = "C:\Temp\process.xml" Get-Process | Export-Clixml -path $xmlFile -Force notepad $xmlFile
How it works...
PowerShell provides a few cmdlets that support exporting data to files of different formats. Export-Csv
saves information to a comma-separated value file, and Export-Clixml
exports
the piped data to XML.
$csvFile = "C:\Temp\sample.csv" Get-Process | Export-Csv -Path $csvFile -Force -NoTypeInformation notepad $csvFile $xmlFile = "C:\Temp\process.xml" Get-Process | Export-Clixml -Path $xmlFile -Force notepad $xmlFile
The Export-Csv
cmdlet converts each...