Try this version of that script. It corrects the comparison operator in the -Filter parameter and adds the necessary "-ErrorAction STOP" to the Set-ADUser cmdlet. Without the ErrorAction the Set-ADUser won't throw a non-terminating exception and the Catch block will never be run.
#Get CSV content
$CSVrecords = Import-Csv "C:\Test.csv" -Delimiter ";"
#Create arrays for skipped and failed users
$SkippedUsers = @()
$FailedUsers = @()
#Loop trough CSV records
foreach ($CSVrecord in $CSVrecords) {
$upn = $CSVrecord.UserPrincipalName
$user = Get-ADUser -Filter "userPrincipalName -eq '$upn'"
if ($user) {
try {
$user | Set-ADUser -Department $CSVrecord.Department -TelephoneNumber $CSVrecord.TelephoneNumber -ErrorAction STOP
}
catch {
$FailedUsers += $upn
Write-Warning "$upn user found, but FAILED to update."
}
}
else {
Write-Warning "$upn not found, skipped"
$SkippedUsers += $upn
}