E
E
Elena Bulikova2018-10-02 16:52:57
PowerShell
Elena Bulikova, 2018-10-02 16:52:57

How to fill in the Manager field automatically?

Good afternoon!
We have a csv file with columns sn, GivenName, Department, title, OfficePhone, Mobile Phone, Manager, City, EmailAddress
We are looking for users in AD by e-mail and fill it with data from the file. It is required to fill in all fields (except sn, GivenName). There is a script:
Import-Module activedirectory
Import-Csv "C:\user.csv" | Foreach {
$EmailAddress = $_."EmailAddress"
$s = [adsisearcher]"(mail=$EmailAddress)"
try {
$u = $s.FindOne().GetDirectoryEntry()
$u.Put("title", $ _.title)
$u.Put("l", $_.city)
$u.Put("department", $_.department)
$u.Put("telephonenumber", $_.officePhone)
$u.Put ("
}
catch {
Write-Host -Fore Yellow "User with e-mail $EmailAddress not found"
}
}
There are no problems with fields having a text value, but the Manager field in the user card (Manager) assumes the choice of an account from AD. In the file from which we take the data, the manager column looks like Last name First name (same as CN) Help to finalize the script

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
strangerror, 2018-10-11
@strangerror

Manager also contains a text value, so recording should not cause problems.
If you try to do this:

$u.Put("Manager","CN=$($_.Manager),OU=Users,DC=XXX,DC=XXX")

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question