This code assumes that the value in the "EmployeeName" column of the CSV is a display name and that there may be more than one employee that has the same name. It also correctly quotes the two filter strings.
Import-csv "c:\temp\User_Update_test.csv" |
ForEach-Object{
$EmployeeDN = (Get-ADUser -filter "DisplayName -eq '$($_.EmployeeName)'").DistinguishedName
$ManagerDN = (Get-ADUser -filter "UserPrincipalName -eq '$($_.ManagerUPN)'").DistinguishedName
if ($EmployeeDN -and $ManagerDN -and $EmployeeDN -isnot [array]){
$props = @{
Identity = $EmployeeDN
Manager = $ManagerDN
Title = $_.EmployeeTitle
Department = $_.EmployeeDepartment
Office = $_.EmployeeLocation
}
Set-ADUser @props
}
else {
Write-Host "Either the employee $($_.EmployeeName) or the manager $($_.ManagerUPN) could not be found in the AD\n or more than one user has the same display name: \n$($EmployeeDN)" -ForegroundColor Yellow
}
}