我有一个我想根据用户输入引用的csv文件。用户将键入员工的姓名,我希望它返回与该员工关联的薪资部门编号。我需要使用的3列标题为First,Last,Payroll Department Number。我做错了什么?
这就是我所拥有的:
$csv = import-csv c:\employees.csv
$First = read-host 'What is the users first name?'
$Last = read-host 'What is the users last name?'
$csv | where {$_.last -eq $Last; $_.'First Name' -eq $First} |
% "Payroll Department Number"
答案 0 :(得分:0)
使用Where-Object
运算符替换-and
条件中的分号,并将ForEach-Object
语句替换为Select-Object
:
$csv | Where-Object { $_.last -eq $Last -and $_.'First Name' -eq $First } |
Select-Object -Expand 'Payroll Department Number'