Why does Excel split an Active Directory distinguished name when opening my PowerShell CSV?

September 23, 2026 3 answers
Asked by argv_04
I'm using Get-ADComputer to export computer information to a CSV with Name, operating system, creation date, and DistinguishedName columns. I set Export-Csv to use a semicolon as the delimiter, but when I open the file in Excel, the distinguished nameโ€”such as CN=PC1,OU=Desktops,DC=officeโ€”is split at its commas. I tried manually adding escaped quotes around the values, but the quotes and backticks appeared in the CSV instead. My export command is: $computerData | Sort-Object -Property Name | Export-Csv $outputFile -NoTypeInformation -Delimiter ";" How can I keep the distinguished name in one column when opening the CSV in Excel?

Answers

!crop16x9
The object construction looks fine. Keep DistinguishedName as the original string and let Export-Csv handle quoting. Manually inserting quote characters changes the data itself, which is why the quotes and backticks show up in the spreadsheet. If you want an easier-to-read AD location, you could also export CanonicalName, optionally removing the final computer-name component.
Reply to this answer
page+fault2
Export-Csv is already designed to quote fields when necessary, so don't add escaped quotes inside the calculated properties. The likely problem is that Excel is using a comma as its list separator while the file was written with semicolons. Change the Windows regional List separator to a semicolon, then reopen the file. Excel should treat the semicolons as column separators and preserve the commas inside the distinguished name.

argv_04: That explains itโ€”the file was being interpreted with Excel's configured separator instead of the delimiter supplied to Export-Csv.

Reply to this answer
ramp.9percent
You can avoid locale-dependent CSV behavior by exporting with a tab delimiter instead: $computerData | Sort-Object Name | Export-Csv $outputFile -NoTypeInformation -Delimiter "`t" Open the result as a tab-delimited file in Excel. The DN's commas will then remain part of the same field.
Reply to this answer

Add your answer

Answers are reviewed before publication.

Related Discussions