Okay, let's try this version. The AD filter has always been quirky. This one contains an additional bit of data validation:
Import-Module ActiveDirectory # this probably isn't necessary any longer
$OU = 'OU=Objetos Arquivados,OU=BHZ,OU=MG,DC=academico,DC=educacao,DC=elv,DC=intranet'
$Users = "C:\Users\joao.victor\Documents\leiaute.csv"
Import-Csv $Users -Header UserPrincipalName, title | # "Header" is only necessary if the CSV doesn't have a header row
ForEach-Object{
if ($_.UserPrincipalName.trim().length -ge 3){
$upn = $_.UserPrincipalName.trim()
if ($u = Get-ADUser -Filter {UserPrincipalName -eq $upn} -SearchBase $OU){ # "UPN" is unique. Using "-like" isn't necessary
$u | Set-ADUser -Title $_.title
}
else{
Write-Host "Could not locate user: " $upn
}
}
else{
Write-Host "The UserPrincipalName '$($_.UserPrincipalName)' is either empty or too short"
}
}