1

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

旧文件:

"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) 

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

4

1 回答 1

3

Import-CsvPSCustomObject将返回一个具有称为CanonicalNameand的属性的数组LastSet

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 <=
于 2019-12-07T23:45:32.343 回答