Compare-Object outputs only the SideIndicators symbols

Hello guys,

I’m having a very annoying problem using the Compare-Object cmdlet:

I have built a function within a custom module.
At the end of the function I’m using Compare-Object to compare the content from 2 files:

$file1 = Get-content "C:\file1.sbs" 
$file2 = Get-content "C:\file2.sbs"   
Compare-Object $file1 $file2

the $file1.sbs file contains text << $file1.sbs will be a collection of string objects (each line will be an object)
the $file2.sbs file contains text << $file2.sbs will be a collection of string objects (each line will be an object)

Between the two files there is only one line that is different (a server name)
Compare objects seems to find it but it outputs only the SideIndicators symbols => <= (one on each line).
So the InputObject header + InputObject data + the SideIndicator header are missing. Only two “=>” “<=” are displayed in the middle of the row on the console.

The $file1 and $file2 objects seems to be ok.
I’ve also defined them as global variables in the function so they can live after the function execution is completed and I’ve run

Compare-Object $file1 $file2

directly from the console and it is working fine. The Output is as expected, includes all headers and data.

I’ve also run

Compare-Object $file1 $file2 | gm

inside the function and I’ve got only the data from the Name column without the “Name” header:

Equals       
GetHashCode  
GetType      
ToString     
InputObject  
SideIndicator

No MemberType or Definition columns!

Do you have any idea what may be the cause ?

Could you please post your code without any unmarked comments and formatted as code?
Place the cursor on an empty line, click the preformatted text button ( </> ) and paste your code.

Please do not create a new post - edit your existing one and correct the formatting.

Thanks in advance.