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...
These are the steps required to export to CSV and XML:
- Open PowerShell ISE as an administrator.
- Add the following script and run it:
$csvFile = "C:\Temp\sample.csv" Get-Process | Export-Csv -path $csvFile -Force -NoTypeInformation #display text file in notepad notepad $csvFile $xmlFile = "C:\Temp\process.xml" Get-Process | Export-Clixml -path $xmlFile -Force #display text file in notepad notepad $xmlFile
How it works...
PowerShell provides a few cmdlets that support exporting data to files of different formats. The Export-Csv
cmdlet saves information to a comma-separated value file, and the Export-Clixml
cmdlet exports the piped data to XML:
$csvFile = "C:\Temp\sample.csv" Get-Process | Export-Csv -path $csvFile -Force -NoTypeInformation #display text file in notepad notepad $csvFile $xmlFile = "C:\Temp\process.xml" Get...