我正在比较 .JSON 文件,使用Compare-Object
如下:
# Compare two files
$BLF = (Get-Content -Path C:\Users\...\Documents\Android1.json)
$CLF = (Get-Content -Path C:\Users\...\Documents\Android2.json)
$a = Compare-Object -ReferenceObject $BLF -DifferenceObject $CLF -IncludeEqual
然后$a
是一个System.Array
。它包含 .JSON 文件中的所有行,每个都位于一个 中InputObject
,并SideIndicator
显示差异。因此,对于诸如
# From file 1
"workProfilePasswordMinimumLength": false,
"workProfilePasswordMinLowerCaseCharacters": false,
"workProfilePasswordMinUpperCaseCharacters": null,
"deviceManagementApplicabilityRuleOsEdition": null,
# From file 2
"workProfilePasswordMinimumLength": true,
"workProfilePasswordMinLowerCaseCharacters": false,
"workProfilePasswordMinUpperCaseCharacters": null,
"deviceManagementApplicabilityRuleOsEdition": true,
比较函数给出使用
$a.psobject.ImmediateBaseObject
输出:
InputObject SideIndicator
----------- -------------
"workProfilePasswordMinLowerCaseCharacters": false, ==
"workProfilePasswordMinUpperCaseCharacters": null, ==
"workProfilePasswordMinimumLength": true, =>
"deviceManagementApplicabilityRuleOsEdition": true, =>
"workProfilePasswordMinimumLength": false, <=
"deviceManagementApplicabilityRuleOsEdition": null, <=
我的问题是:我想对这些 InputObjects 进行排序,使它们如下所示:
InputObject SideIndicator
----------- -------------
"workProfilePasswordMinLowerCaseCharacters": false, ==
"workProfilePasswordMinUpperCaseCharacters": null, ==
"workProfilePasswordMinimumLength": true, =>
"workProfilePasswordMinimumLength": false, <=
"deviceManagementApplicabilityRuleOsEdition": true, =>
"deviceManagementApplicabilityRuleOsEdition": null, <=
以便在变量不同时对匹配的名称进行排序。我怎样才能对它们进行排序?