Benjamin Benjamin - 1 year ago 122
PowerShell Question

Export CSV File

I want to export some data with Powershell to upload them to a online-portal. I'am using Export-CSV function to export a Variable with the content to a csv file which i can upload to the portal.

String to Export the previously collected data:

$Content | Export-Csv -Path c:\temp\content.csv -NoTypeInformation

The Export File (Export.csv) looks like this:

Serial Number,Device Name / Hostname,Tags,Notes
FTX123456A1,My Cisco Router,System,System1

The CSV is looking good at this point. When I tried to upload the file I't was not proceed by the platform.

I opened the CSV in Excel and noticed that the Filetype was "Unicode Text (*.txt)" when I pressed "Save As". Which is weird because the filetype was definitly CSV. I changed the option to "CSV - separated" and uploaded the file again. Now everything worked perfectly. How can i define this more specific definition of a filetype in Powershell?

Thanks for any help in advance!

Answer Source
$Content | Export-Csv -Path c:\temp\content.csv -NoTypeInformation -encoding UTF8

As above would specify the encoding to UTF8

Source (and to see diffrent encoding types):

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download