需要帮助应用foreach statememt

时间:2016-02-26 20:13:02

标签: powershell foreach

我有一个脚本,它引用两个单独的csv文件来获取员工信息。该脚本将搜索员工的姓名,并从csv1返回员工代码,并说明如果在csv2中找到他们所在的公司。我希望能够为使用外卡时符合搜索条件的每个员工运行两行代码。只有一名员工才能找到该脚本。我似乎无法弄清楚如何为$ res中找到的每个项目运行最后两个语句。

$csv1 = import-csv .\employees.csv
$csv2 = import-csv .\companyB.csv
$First = read-host 'What is the users first name?'
$Last = read-host 'What is the users last name?'
$res = $csv1 | Where-Object { $_.'last name' -like $Last -and $_.'First Name' -like $First } 
$res1 = $csv2 | Where-Object { $_.'last name' -like $Last -and $_.'First Name' -like $First }

if($res -eq $null) { Write-Host "User does not exist" }
else { $res | Select-Object 'Payroll Department Number','Last Name','First name' }

if($res1 -eq $null) { Write-Host "User is a Company A employee" }
else { Write-Host "User is a Company B employee" }
}

0 个答案:

没有答案