gpt4 book ai didi

powershell - 如何获得两个两个元素数据集之间的不同对象?

转载 作者:行者123 更新时间:2023-12-03 00:59:00 25 4
gpt4 key购买 nike

如果我有包含以下数据集的这两个文件:

旧文件:

"CanonicalName","LastSet"
"CONTOSO.com/NA/US/OU1/Users/Active/Test User","2019-07-02 14:14:44"
"CONTOSO.com/NA/US/OU1/Users/Active/User One","2019-07-02 14:14:44"
"CONTOSO.com/NA/US/OU2/Users/Active/User Two","2018-09-02 05:53:35"
"CONTOSO.com/OC/AU/OU3/Users/User Three","2017-06-23 14:20:07"

临时文件:
"CanonicalName","LastSet"
"CONTOSO.com/NA/US/OU1/Users/Active/User One","2019-07-02 14:14:44"
"CONTOSO.com/NA/US/OU2/Users/Active/User Two","2018-09-02 05:53:35"
"CONTOSO.com/OC/AU/OU3/Users/User Three","2017-06-23 14:20:07"

返回:
InputObject                                                                                  SideIndicator
----------- -------------
@{CanonicalName=CONTOSO.com/OC/AU/OU3/Users/User Three; LastSet=2017-06-23 14:20:07} <=

当执行以下代码时,我期望它以“<=”返回TEST用户的位置:
Compare-Object -ReferenceObject (import-csv $oldfile) -DifferenceObject (import-csv $tempfile) 

为什么?如何获得所需的输出? DIFFERENT对象。

最佳答案

Import-Csv将返回PSCustomObject数组,该数组具有名为CanonicalNameLastSet的属性。

Compare-Object必须将复杂对象与属性进行比较时,您需要使用-Property参数来告诉它在进行相等性测试时要比较哪些属性:

Compare-Object -ReferenceObject (Import-Csv $oldfile) -DifferenceObject (Import-Csv $tempfile) -Property CanonicalName,LastSet

结果是:
CanonicalName                                LastSet             SideIndicator
------------- ------- -------------
CONTOSO.com/NA/US/OU1/Users/Active/Test User 2019-07-02 14:14:44 <=

关于powershell - 如何获得两个两个元素数据集之间的不同对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59230386/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com