3

Lately on some Windows 10 machines I noticed that Get-Service | Export-Csv "C:\users\[xxx]" creates a .csv file that if opened in Excel displays all properties just in column A. I'm used to seeing each property being output to a separate column.

The Windows and Office versions on both machines are identical. Windows: 1709 (Build 16299.431) Office: 1802 (Build 9029.2253 CTR)

Excel-Online also displays the output in one column.

Right-clicking the .csv file on each machine shows diffrent file types: "CSV-File (.csv)" which displays multiple columns versus "Microsoft Excel-CSV-File(.csv)" which opens in one column.

Moreover, the file icons are different.

enter image description here for the machines where it displays multiple columns and enter image description here for machines where it displays in one column.

Has anybody experienced this and knows why that might be?

I'm consfused as to which is the correct behaviour.

Thanks for your input.

2 Answers 2

5

Export-CSV uses , to seperate columns, while excel wants ; as seperators.

The easiest way for you to handle the situation is to use this instead:

Export-Csv "C:\users\[xxx]" -Delimiter ';'

This will create the .csv file with ; instead of ,.

You probaly have different default delimiters on the two machines, the answer here explains it pretty well: How to get Excel to interpret the comma as a default delimiter in CSV files?

Sign up to request clarification or add additional context in comments.

4 Comments

Interesting. I used -Delimiter ';' and now it's the other way around. The file now opens everything in one column for the machine where it had been multiple columns before and vice versa on the other machine. Any idea why Excel uses different delimiters on different machines? Could it have to do with the file extensions and icons I mentioned in my initial post?
@colonel_claypoo Take a look at superuser.com/questions/606272/…
Select the one column, then the data tab from the ribbon, then text to columns and you will go through the wizard. As for the delimiter attribute I am using the "|" because sometimes my data can contain a semi colon or a comma.
@Paxz: Thank you, that's the answer. Much appreciated.
1

The problem for me came from the encoding the csv file is written in. When I used Out-File in PowerShell it encoded in UCS-2 Little Endian and everything ended up in one column.

My solution for you would be along these lines:

Get-Service | Export-Csv -Path "C:\users\[xxx]" -NoTypeInformation -Encoding UTF8 -Force

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.