How can Update manger name of bulk user from csv file in Active directory through powershell?

Answered How can Update manger name of bulk user from csv file in Active directory through powershell?

  • Monday, January 07, 2013 10:09 PM
     
     

    How can Update manger name of bulk user from csv file in Active directory through powershell?

    see csv file format:

    sAMAccountName,Manager
    saruabh,Santosh

All Replies

  • Monday, January 07, 2013 10:13 PM
    Moderator
     
     

    What have you tried so far, and with what results?

    Bill

  • Monday, January 07, 2013 10:37 PM
     
      Has Code

    I used below script

    $list = Import-Csv .\User-Manager.csv
    
    $list | Foreach { $boss = Get-ADUser -Identity $_.Manager ; Set-ADUser -Identity $_.User -Replace @{manager=$boss.DistinguishedName} }

    But getting below error:

    PS E:\script> .\Managerupdate.ps1
    Set-ADUser : Cannot validate argument on parameter 'Identity'. The argument is
    null. Supply a non-null argument and try the command again.
    At E:\gc\Managerupdate.ps1:3 char:81
    + $list | Foreach { $boss = Get-ADUser -Identity $_.Manager ; Set-ADUser -Ident
    ity <<<<  $_.User -Replace @{manager=$boss.DistinguishedName} }
        + CategoryInfo          : InvalidData: (:) [Set-ADUser], ParameterBindingV
       alidationException
        + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.Activ
       eDirectory.Management.Commands.SetADUser


  • Monday, January 07, 2013 10:42 PM
    Moderator
     
     

    Hi,

    Do you have a blank or empty attribute in your CSV file?

    Bill

  • Monday, January 07, 2013 11:02 PM
    Moderator
     
     Answered Has Code

    Here is what I just suggested in the PowerShell forum:

    $list = Import-Csv .\User-Manager.csv

    ForEach ($Item In $List) { $boss = Get-ADUser -Identity $Item.Manager ; Set-ADUser -Identity $Item.User -Replace @{manager=$boss.DistinguishedName} }

    -----

    Best to only post in one forum, until resolved or you are redirected to another.


    Richard Mueller - MVP Directory Services

  • Monday, January 07, 2013 11:27 PM
     
     
    Hi Getting below error: Unexpected token 'in' in expression or statement. At line:1 char:59 + $list = Get-Content e:\gc\userlist.txt | ForEach ($Item In <<<< $list) { $bo ss = Get-ADUser -Identity $Item.Manager ; Set-ADUser -Identity $Item.User -Repl ace @{manager=$boss.DistinguishedName} } + CategoryInfo : ParserError: (in:String) [], ParentContainsError RecordException + FullyQualifiedErrorId : UnexpectedToken
  • Tuesday, January 08, 2013 12:49 AM
     
     
    Hi Getting below error: Unexpected token 'in' in expression or statement. At line:1 char:59 + $list = Get-Content e:\gc\userlist.txt | ForEach ($Item In <<<< $list) { $bo ss = Get-ADUser -Identity $Item.Manager ; Set-ADUser -Identity $Item.User -Repl ace @{manager=$boss.DistinguishedName} } + CategoryInfo : ParserError: (in:String) [], ParentContainsError RecordException + FullyQualifiedErrorId : UnexpectedToken

    $list is null?

    foreach($item in $list){...}

    NOT foreach($item in ln $list)

    I not L - IN not LN.


    Happy New Year ¯\_(ツ)_/¯


  • Tuesday, January 08, 2013 1:14 AM
     
     

    Hey,

    Thanks for your help..

    I got it by my own with below script.

    ========

    $list = Import-Csv "e:\gc\userlist.csv" | % {
    $User = $_.sAMAccountName
    $ID = $_.manager
    Set-ADUser $User -manager $ID
    }

    =================

    This link helped me to achieved this.

    http://portal.sivarajan.com/2011/07/add-employee-idpowershell-script.html