Why PowerShell’s ConvertFrom‑Csv Reports Duplicate “State” Columns and How to Resolve It
The article explains why PowerShell’s ConvertFrom‑Csv fails with a duplicate “状态” (state) column, how the issue stems from language translation of column names, and provides a practical workaround using custom headers and Out‑GridView to display driver information.
While experimenting with a PowerShell GridView example from a blog, the author encountered an error stating that the "状态" (state) column already exists. The root cause is that PowerShell’s ConvertFrom‑Csv requires unique column names, and on English‑language systems the fields "state" and "status" are both translated to the Chinese word "状态", creating a duplicate.
To verify the problem, the author ran the command on an English‑language machine, confirming that both "state" and "status" become "状态" after translation, which violates the uniqueness rule of ConvertFrom‑Csv. The article notes that while the translation is technically correct, it does not follow PowerShell’s expectations.
As a solution, the author adds a custom header list to the CSV conversion, ensuring each column has a distinct name. The command used is:
Driverquery.exe /v /FO CSV | ConvertFrom‑Csv -Header "模块名","显示名称","描述","驱动程序类型","启动模式","状态","状态s","接受停止","接受暂停","分页池(字节)","代码(字节)","BSS(字节)","链接日期","路径","Init(字节)" | select "模块名","显示名称","描述","驱动程序类型","启动模式","状态","状态s","接受停止" | Out‑GridView -title "装逼大师"This command pipes the detailed driver list from driverquery.exe into ConvertFrom‑Csv with an explicit header array, selects the desired columns, and finally displays the result in an interactive GridView window.
The output shows that the first row (the header) is not exactly as expected, but the remaining data is correct, meaning the original requirement is essentially fulfilled.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
ITPUB
Official ITPUB account sharing technical insights, community news, and exciting events.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
