Powershell 2 处理多个 csv 文件

powershell 2 working with multiple csv files

我有 2 个 csv 文件。一个有名字,另一个有 phone 个号码的列表。我正在尝试遍历每个 csv 文件和 运行 关于用户和名称的脚本。

file examples
Name Number
a      1
b      2
c      3

所以我需要 运行 像 a + 1, b + 2, c + 3 这样的脚本

尝试使用 foreach 循环,但它无法正常工作,它嵌套不正确,无法弄清楚。

 if ($users){
foreach ($u in $users) 
{ 
 $username= ($u.'Mail')

  
     foreach ($n in $numbers)
     { 
    
    $number = ($n.'ID')
   
     }  

你很接近,因为你需要使用一个循环,但你想要一个循环从两个文件中获取数据,所以在这种情况下你最好使用这样的 For 循环:

$Combined = For($i = 0; $i -lt $users.count; $i++) {
    $Props = @{
        Mail = $users[$i].Mail
        ID = $numbers[$i].ID
    }
    New-Object PSObject -Prop $Props
}
$Combined | Export-Csv C:\Path\To\Combined.csv -NoTypeInfo