Uppdate ad with xml file

Okay, this is it.
I have an xml file containing users already in ad but with changes. It should be imported and ad updated.
But in that file there are also people who should not be updated for they belong to “wrong” ou.
I need to check these against ad and the only index key I have is samaccountname.
I have done the following but am not 100% sure it will work. Someone who has the opportunity to see if it looks okay?

$adSwe = Get-ADUser -Filter 'enabled -eq $true' -SearchBase "OU=Sweden,DC=eltel,DC=eltelnetworks,DC=com" -Properties `
samaccountname,
givenname,
sn,
title,
telephonenumber,
mobile,
streetaddress,
postalcode,
l,
co,
c,
countrycode,
company,
manager,
department,
preferredlanguage,
departmentnumber,
employeetype | select samaccountname,
givenname,
sn,
title,
telephonenumber,
mobile,
streetaddress,
postalcode,
l,
co,
c,
countrycode,
company,
@{n='Manager';e={(Get-aduser $_.manager).name}},
#manager,
department,
preferredlanguage,
departmentnumber,
employeetype



$adNo = Get-ADUser -Filter 'enabled -eq $true' -SearchBase "OU=Norway,DC=eltel,DC=eltelnetworks,DC=com" -Properties `
samaccountname,
givenname,
sn,
title,
telephonenumber,
mobile,
streetaddress,
postalcode,
l,
co,
c,
countrycode,
company,
manager,
department,
preferredlanguage,
departmentnumber,
employeetype | select samaccountname,
givenname,
sn,
title,
telephonenumber,
mobile,
streetaddress,
postalcode,
l,
co,
c,
countrycode,
company,
@{n='Manager';e={(Get-aduser $_.manager).name}},
#manager,
department,
preferredlanguage,
departmentnumber,
employeetype

$adSweNo = $adSwe+$adNo

[xml]$XmlDocument = Get-Content -Path .\Eltel_Logica_AD.xml
$xml1 = $XmlDocument.NewDataSet.Table1

foreach($user in $adSweNo){
if ($user -ne $xml1.samaccountname){
$samaccountname = $user.SAMACCOUNTNAME
$firstname = $user.FIRSTNAME
$surname = $user.SURNAME
$title = $user.TITLE.trim()
$telephonenumber = $user.TELEPHONENUMBER
$mobile = $user.MOBILE
$streetaddress = $user.STREETADDRESS
$postcode = $user.POSTCODE
$L = $user.L
$CO = $user.CO
$C = $user.C
$countrycode = $user.COUNTRYCODE
$company = $user.COMPANY
$managerid = $user.MANAGERID
$manager = $user.MANAGER
$department = $user.DEPARTMENT
$preferredlanguage = $user.PREFERREDLANGUAGE
$costcenter = $user.COSTCENTER
$employeetype = $user.EMPLOYEETYPE
$physicalDeliveryOfficeName = $user.COSTCENTER

#And then the other code are working :)
}}

Could you please attach .\Eltel_Logica_AD.xml, So that I can assist with testing it.

Thanks but this is resolved now. :slight_smile: