I am trying to compare two .json files using
# Compare two files
$BLF = (Get-Content -Path C:\Users\...\Documents\Android1.json)
$CLF = (Get-Content -Path C:\Users\...\Documents\Android2.json)
$aUnsorted = Compare-Object -ReferenceObject $BLF -DifferenceObject $CLF -IncludeEqual
I have written code to compare regular variables such as the below "passcodeBlockSimple", and register the value in one file vs the other. I would like to do the same with values that are defined inside brackets:
"variableName": [
"99"
]
I have a solution for when the two files have the same value, by adding onto the value until it finds the end-bracket ]. That gives "variableName": ["99"]. See the variable "roleScopeTagIds" below as an example of such a variable.
I would like to find the value when they are different, but the output from Compare-Object lists the difference line-by-line. Example below, where I loose the information about the variable "restrictedApps" when it is different in the two files (File1 has value "1" and File2 has Value "2").
InputObject SideIndicator
----------- -------------
"@odata.type": "#microsoft.graph.iosCompliancePolicy", ==
"roleScopeTagIds": [ ==
"0" ==
], ==
"version": 1, ==
"passcodeMinutesOfInactivityBeforeScreenTimeout": 1, ==
"managedEmailProfileRequired": false, ==
"restrictedApps": [ ==
], ==
"passcodeBlockSimple": false, =>
"2" =>
"passcodeBlockSimple": true, <=
"1" <=
The files are, File 1:
"@odata.type": "#microsoft.graph.iosCompliancePolicy",
"roleScopeTagIds": [
"0"
],
"version": 1,
"passcodeBlockSimple": true,
"passcodeMinutesOfInactivityBeforeScreenTimeout": 1,
"managedEmailProfileRequired": false,
"restrictedApps": [
"1"
],
And File 2:
"@odata.type": "#microsoft.graph.iosCompliancePolicy",
"roleScopeTagIds": [
"0"
],
"version": 1,
"passcodeBlockSimple": false,
"passcodeMinutesOfInactivityBeforeScreenTimeout": 1,
"managedEmailProfileRequired": false,
"restrictedApps": [
"2"
],
So my question is: How can i find the value of the variable when they are different, and the Compare-Object result is as above?
(I have to use the Compare-Object function)