Hello,
You can do it what you will have to do is:
- Search for the manager user based on the email address
- Modify the target user manager with the previously user object you get from 1
Below an example :
$CSV = Import-Csv -path Example_csv.csv -Delimiter ";"
foreach($line in $CSV) {
$Manager = Get-ADUser -LDAPFilter "(mail=$($line.UserEmail))"
Set-ADUser xxx -Manager $Manager
}
My CSV look like this :
UserEmail;ManagerFullname
john@keyman .com;Tim Wang
Regards,
Ok now I understand better :)
If the email address match the userprincipalname yes you can use it instead, below another example :
$CSV = Import-Csv -Path Example_csv.csv -Delimiter ";"
foreach($line in $CSV) {
$Manager = Get-ADUser -Filter "Name -like '$($line.ManagerFullname)'"
$TargetUser = Get-ADUser -Filter "UserPrincipalName -like '$($line.UserEmail)'"
if(@($Manager).Count -lt 2) {
Set-ADUSer $TargetUser -Manager $Manager
} else {
Write-Output "More than 1 user exist with this name $($line.ManagerFullname)"
}
}