用于比较 csv 并附加信息的 Powershell



我有两个CSV文件。一种是"术语列表",每天都在变化。它有多个标头,其中可能包含也可能不包含任何信息,但也包括电子邮件地址。另一个CSV是"webccmaster"。它有 2 列:电子邮件地址和它来自的网络cc。我正在将电子邮件地址与术语列表的电子邮件地址进行比较。我希望输出也显示 webcc 列,但我认为我错过了一些东西。我的代码如下:

  if (Test-Path C:Scriptstermlist.csv) 
  {
     $termlist = import-csv "c:scriptstermlist.csv" -header("User Name", "Brazil_inst", "Emp Num", "Emp Name", "Email Address", "Term Dt", "Plant", "Deptt", "Location", 
      "Region", "Job Name", "Sup. Name", "Phone Number") | where-Object {$_."Email Address" -ne ''} | sort "Email Address"
  if (Test-Path C:Scriptsmasterwebcc.csv)
     {    
    $webcclist = import-csv "c:scriptsmasterwebcc.csv" | sort "Email Address" -unique
    Compare-Object $termlist $webcclist -property "Email Address" -IncludeEqual 
    Remove-Item "c:scriptstermlist.csv"
    get-childitem C:UsersjoshDownloads -include Consolidated*.xls -recurse | foreach ($_) {remove-item $_.fullname}
      } else {Write-warning "C:Scriptsmasterwebcc does not exist"}
   } else { Write-warning "C:Scriptstermlist does not exist"}

读取主机 - 提示"按回车退出"

我知道我会想要摆脱 -unique 约束,但为了简单起见,此时就在那里,因为我也无法显示"webcc"列。我也想知道是否有办法只显示它在两个 CSV 中发现相等的项目。感谢您给我的任何帮助或提示。

在电子邮件上联接表,对吧?

表.csv:

mail@mail.net|SomethingAboutSite

表B.csv:

mail@mail.net|Data1|Data2|Data3

像这样的代码

$EmailToSiteAssignment = @{}
Import-CSV -Path 'TableA.csv' -Header @('email','site') | ForEach-Object {$EmailToSiteAssignment[$_.email.Trim().toLower()]=$_.site}
$Result = @();
Import-CSV -Path 'TableB.csv' -Header @('email','data1','data2','data3') | ForEach-Object {$Result += @( $_ | Add-Member -MemberType NoteProperty -Name 'site' -Value $EmailToSiteAssignment[$_.email.Trim().ToLower()] ) }

相关内容

  • 没有找到相关文章

最新更新