Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Compare-object strange behaviour

$
0
0

I compare two xml documents in my script that provide me with BIOS settings. I basically look for differences between a reference xml in central location and xmls on remote machines. When the script runs it checks if the value assigned to a variable which holds the results of running the compare-object cmdlet and if it's $Null the test is passed. However when I run the script I often find that when I display the result I get empty line yet the test fails. I run the script in debugging mode so when the comparison goes through and I see the empty line indicating the test being negative I call the value of my test variable and it actually shows me some differences. It gets even worse when for a test I copied over my reference xml to the target machine to be sure they're identical. When I run the scrip again I get empty line after compare-object where I call the value but when I call the value again from the debugging prompt I'm seeing differences.

Since my machines are HP I use conrep to generate the xmls. I then read them 

[xml]$ref = Get-Content .\ref.xml

and

$reference =  $ref.conrep.section | select name, "#text"  # to create a reference object

Similarly for diff object and then

$result = Compare-Object $reference $difference -PassThru

$result  # when the code runs normally this is where I get empty line suggesting all is good.

Unfortunately I can't post the xmls - compliance.


Viewing all articles
Browse latest Browse all 6937

Trending Articles