Compare-Object don't work

I have an xml file to read in to ad. The hard part is that what is stated in the xml file is what applies. First, it must be checked that no countries other than Norway and Sweden are updated. No problem with that. But in ad it can say that a certain user belongs to Sweden but in the xml file it says for example. Finland and then it is the one in the xml file that should apply and it should not be updated and it is this particular control i have problems with. Anyone have an idea?
Now I have don'e that control something like this. And I can't get this to work.

#Importing AD
Import-Module ActiveDirectory

[xml]$XmlDocument = Get-Content -Path c:\scripts\users.xml
$xml1 = $XmlDocument.NewDataSet.Table1

#Importing AD Users
$adusers = Get-ADUser -Filter * -Properties * | Where Country -NE $null

#Compare - column SamAccountName
$Results = Compare-Object $xml1 $adusers -Property SamAccountName,Country -IncludeEqual

$Array = @()
Foreach($R in $Results)
If( $R.sideindicator -eq “==” )
$Object = [pscustomobject][ordered] @{

Username = $R.SamAccountName
“Compare indicator” = $R.sideindicator
Country = $R.Country

$Array += $Object

#Count users in both files
#($Array | sort-object username | Select-Object * -Unique).count

#Display results in console

Please format your code as code by using the code (pre) tag button provided on the edit bar of the post editor. Thanks.

Are you sure Compare-Object works the way you expect it? If you only need the equal elements from both objects you can add the parameter -ExcludeDifferent. Additionally you could add -PassThru to get the input object as output as well.

Ok sorry for not pre tag first time in here.

I still can’t get this to work. It shows me either <= or => as sideindicator if I want to select == it wount work even if the country are like in file and in ad then it just show nothing.

And this is the problem it shall only get info that are alike == nothing else. If ther are difference between file and ad in country then it shall not show that at all.

Is there a special reason why you are using XML formatted data? Most people would choose CSV for structured data and for comparison. Espcially because the code line you commented with #Importing AD Users creates a structured data set from the AD.

Yes! This is because the management program used by the customer only spits out file in xml.
And yes I would prefere csv but that is not my choice.

Right now I am away on work but I can upload the whole code for display if that helps.

Just get rid of some details.

You cannot post XML formatted data here in the forum. You will have to upload it to GitHubGist and share it this way here.

I did mean the Powershell code in total

OK, but without seeing at least the sctructure of the XML data you have to deal with it will be unlikely to help you.

Ok. I will try to get it uploaded on GitHub. Thanks

Instead of using an if clause to compare if the side indicator is the desired one, have you tried piping it through Where-Object instead?

I ran into this issue with a script I wrote at work, and I don’t have access to our private github right now, but it I remember on Monday I’ll check the code.

However, I seem to remember that Where-Object was the thing that finally worked for me. Trying to use comparison operators and if clauses on special charectors like the side indicator would not return $True even when you expect it to, but Where-Object did work.

$Results | Where-Object {$_.SideIndicator -like '=='} | Select-Object -ExpandProperty InputObject

If I’m way off base we can help better once we have a sanitized copy of your XML. Please do not share your actual AD userids online