Script to change -manager attribute in AD

I am trying to put together a script that takes a csv from our HR system and updates attributed in AD. I have been using syntax like this for other attributes with no issues:

Import-Csv $Importedcsv | ForEach-Object {
Set-QADUser $_.mail -manager $_.Supervisor_Primary `
-ObjectAttributes @{ExtensionAttribute1=($_.ExtensionAttribute1);
ExtensionAttribute2=($_.ExtensionAttribute2)}
}

I have a csv from HR that has the following format:

The issue that we are running into is that the attributes that are coming from our HR systems do not coincide with anything we have in AD. How do we populate the -manager attribute using data from this csv?

Thanks for everyone's help!

Brian

August 24th, 2015 3:28pm

Hi Brian,

You might be able to split the data in that cell and then use a filter like so:

Import-Csv .\input.csv | ForEach {

    $mgr = $_.Supervisor_Primary -split ','

    Get-ADUser -Filter "GivenName -eq '$($mgr[1])' -and Surname -eq '$($mgr[0])'"

}

Free Windows Admin Tool Kit Click here and download it now
August 24th, 2015 3:36pm

Mike's suggestion might work if you have a small number of potential supervisors, their names match the exact attributes set in AD, and there are no duplicates (those are three potential problems I can think of off the top of my head).

A more robust solution is to create a lookup list that contains the Supervisor_Primary list from your HR system and the corresponding sAMAccountName of the matching AD account, and use that to assign the manager attribute instead.

August 24th, 2015 5:51pm

Thanks for both of your posts. We already have two people who have the same last name and first initials so I am unsure that Mike's recommendation will work.

I will start looking at how to build a lookup list.

Thanks

Brian

Free Windows Admin Tool Kit Click here and download it now
August 24th, 2015 6:02pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics