I am comparing .JSON files, using Compare-Object
like this:
# 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
Then $a
is a System.Array
. It contains all the lines in the .JSON files each in an InputObject
, and SideIndicator
to show the difference. Thus for a difference such as
# From file 1
"workProfilePasswordMinimumLength": false,
"workProfilePasswordMinLowerCaseCharacters": false,
"workProfilePasswordMinUpperCaseCharacters": null,
"deviceManagementApplicabilityRuleOsEdition": null,
# From file 2
"workProfilePasswordMinimumLength": true,
"workProfilePasswordMinLowerCaseCharacters": false,
"workProfilePasswordMinUpperCaseCharacters": null,
"deviceManagementApplicabilityRuleOsEdition": true,
the compare function gives using
$a.psobject.ImmediateBaseObject
the output:
InputObject SideIndicator
----------- -------------
"workProfilePasswordMinLowerCaseCharacters": false, ==
"workProfilePasswordMinUpperCaseCharacters": null, ==
"workProfilePasswordMinimumLength": true, =>
"deviceManagementApplicabilityRuleOsEdition": true, =>
"workProfilePasswordMinimumLength": false, <=
"deviceManagementApplicabilityRuleOsEdition": null, <=
My probem is: I want to sort these InputObjects so that they are like this:
InputObject SideIndicator
----------- -------------
"workProfilePasswordMinLowerCaseCharacters": false, ==
"workProfilePasswordMinUpperCaseCharacters": null, ==
"workProfilePasswordMinimumLength": true, =>
"workProfilePasswordMinimumLength": false, <=
"deviceManagementApplicabilityRuleOsEdition": true, =>
"deviceManagementApplicabilityRuleOsEdition": null, <=
So that the matching names, when the variables are different, are sorted. How can I sort them?