本文介绍了如何在此上使用组对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试从 $ f
中获取与 $ table4
中的帐户不匹配的所有帐户到 $ accounts
中.但是我还需要检查入住人数是否匹配.
I am trying to get all the accounts from $f
which do not match the accounts in $table4
into $accounts
. But I need to also check if the occupancy number matches or not.
CSV $ f
:
Account_no |occupant_code
-----------|------------
12345 | 1
67890 | 2
45678 | 3
DataTable $ table4
DataTable $table4
Account_no |occupant_code
-----------|------------
12345 | 1
67890 | 1
45678 | 3
当前代码:
$accounts = Import-Csv $f |
select account_no, occupant_code |
where { $table4.account_no -notcontains $_.account_no }
这需要做的是检查 occupant_code
是否不匹配,即:
What this needs to do is to check that occupant_code
doesn't match, i.e.:
- 12345 :
$ f
和$ table4
的帐户和居住者匹配;因此它被忽略了 - 67890 :帐户匹配
$ table4
,但是occupancy_code不匹配,因此将其添加到$ accounts
.
- 12345: account and occupant from
$f
and$table4
match; so it's ignored - 67890: account matches
$table4
, but occupancy_code does not match, so it is added to$accounts
.
当前结果:
所需结果: 67890
我相信我需要使用 Group-Object
,但是我不知道如何正确使用它.
I believe I need to use Group-Object
, but I do not know how to use that correctly.
我尝试过:
Import-Csv $f |
select account_no, occupant_code |
Group-Object account_no |
Where-Object { $_.Group.occupant_code -notcontains $table4.occupant_code }
推荐答案
比较对象
?
csv1.csv:
Account_no,occupant_code
12345,1
67890,2
45678,3
csv2.csv:
Account_no,occupant_code
12345,1
67890,1
45678,3
PowerShell命令:
PowerShell command:
Compare-Object (Import-Csv .\csv1.csv) (Import-Csv .\csv2.csv) -Property occupant_code -PassThru
输出:
Account_no occupant_code SideIndicator
---------- ------------- -------------
67890 1 =>
67890 2 <=
这篇关于如何在此上使用组对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!