Try it this way:
Import-Csv "C:\Users\Administrator.APC-SERVICES\Desktop\mngimport\Managers1.csv" |
ForEach-Object {
$ADUser = Get-ADUser -Filter "displayname -eq '$($_.ProfessionalFullName)'"
$manager = (Get-ADUser -Filter "displayname -eq '$($_.ManagerFullName)'").distinguishedname
if ($ADUser -and $manager) {
$ADUser | Set-ADUser -manager $manager
}
}
Two things:
- You don't have to explicitly import the ActiveDirectory module. PowerShell (since version 3) will do that automatically.
- Using the DisplayName to identify users is a little bit risky since a display name may not be unique in the AD forest. A samaccountname or primary email address is much better