1

Im trying to populate the manager fields on AD using

Import-Csv C:\Testimport.csv | ForEach-Object {Set-ADUser -Identity $_.samAccountName -Replace @{Manager=$_.manager}}

But I get the following error:

Set-ADUser : Cannot bind parameter 'Replace' to the target. Exception setting " Replace": "Object reference not set to an instance of an object." At line:1 char:95 + Import-Csv C:\Testimport.csv | ForEach-Object {Set-ADUser -Identity $.samAcc ountName -Replace <<<< @{manager=$.manager}} + CategoryInfo : WriteError: (:) [Set-ADUser], ParameterBindingEx ception + FullyQualifiedErrorId : ParameterBindingFailed,Microsoft.ActiveDirectory
.Management.Commands.SetADUser

1
  • Have you tried anything to solve this issue so far? Commented Oct 18, 2014 at 13:34

2 Answers 2

1

Depending on what the Manager is represented by in your csv you can just use the Set-Aduser parameter -Manager on its own.

Import-Csv C:\Testimport.csv | ForEach-Object {Set-ADUser -Identity $_.samAccountName -Manager $_.manager}

If not please show some sample date in your question. This would work in Manager was a account name at least. Also there is an error in the code you ran: manager=$.manager should be manager=$_.manager

Sign up to request clarification or add additional context in comments.

Comments

1

If $_.manager is the Manager sAMAccountName attribute, you need the distinguidhedName attribute to use it later as a value into -Replace parameter:

Import-Csv C:\Testimport.csv | 

ForEach-Object {

    $managerDN = (Get-ADUser $_.manager).distinguishedName

    Set-ADUser -Identity $_.samAccountName -Replace @{Manager=$managerDN}
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.