You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何实现PowerShell比较CSV文件时忽略大小写并保留指定列

解决PowerShell Compare-Object大小写敏感的问题

直接在Compare-Object命令中添加-CaseInsensitive参数,即可实现不区分大小写的属性比较,修改后的完整代码如下:

$ErrStatus = Import-Csv .\StatusErrorResults.csv
$StatLibrary = Import-Csv .\Status_Library.csv

Compare-Object $StatLibrary $ErrStatus -Property Device,Status -IncludeEqual -ExcludeDifferent -PassThru -CaseInsensitive | 
    Select-Object * -ExcludeProperty SideIndicator | 
    Export-Csv -NoTypeInformation .\StatusErrorResultsFiltered.csv

说明

  • -CaseInsensitive参数会让Compare-Object在对比Device和Status属性时忽略大小写差异,避免因大小写不一致导致的内容遗漏。
  • 保留-PassThru参数可确保输出的是$StatLibrary中的原始对象(包含全部三列),后续通过Select-Object排除自动生成的SideIndicator列后,就能完整导出第一个CSV的所有列内容。

内容的提问来源于stack exchange,提问作者BCon995

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.11 06:50:27