To export csv with no header, you can use the ConvertTo-Csv cmdlet in PowerShell to export data to a CSV file with -NoTypeInformation and then the Select-Object command with -Skip parameter to skip the first line, which contains the header information
The following method shows how you can do it with syntax.
Method 1: Export data to CSV with no headers
$processList | ConvertTo-Csv -NoTypeInformation | Select-Object -Skip 1 | Set-Content -Path "C:\temp\log\processList.csv"
This example will export the data stored in the $processList variable to a CSV file named “processList.csv” without including the header information.
The following example shows how you can use this method.
Export CSV with No Header in PowerShell
Use the ConvertTo-Csv cmdlet in PowerShell to convert the objects to CSV format and then the Select-Object cmdlet with the -Skip parameter to skip the first line (header information).
# get the process name and id $processList = Get-Process | Select-Object -Property Name, ID # Convert the process object to a csv format and skip first line $processList | ConvertTo-Csv -NoTypeInformation | Select-Object -Skip 1 | Set-Content -Path "C:\temp\log\processList.csv" # Read the content of the csv Get-Content -Path "C:\temp\log\processList.csv"
Output:
In this script, we retrieve the list of processes using the Get-Process cmdlet and save it to the $processList variable.
We then use the pipe the $processList data to the ConvertTo-Csv cmdlet to convert the objects to CSV format and pipe them to the Select-Object cmdlet again with the -Skip parameter to skip the first line, which contains header information.
Finally, we use the Set-Content cmdlet to write the CSV data to a file.
To verify the csv file content, we use the Get-Content cmdlet to read the content of the CSV file from the specified location. In the screenshot, you can see the exported csv file doesn’t contain the header information.
Conclusion
I hope the above article on exporting CSV with no header information in PowerShell is helpful to you.
PowerShell doesn’t have a built-in parameter -NoHeader in Export-CSV cmdlet, hence we use the ConvertTo-Csv cmdlet in PowerShell.
You can find more topics about Active Directory tools and PowerShell basics on the ActiveDirectoryTools home page.