Forum Discussion

sany98's avatar
sany98
Copper Contributor
May 07, 2021
Solved

Move records from one attribute to another

Hi all,
 
I need to move the records from employeeNumber field to the employeeID field. I would like to run test on one single user and then on whole OU. Is this doable and how? I'm still learning, so any help is appreciated.
  • sany98 

    Yes, everything is doable in PowerShell
    You will get ADUser with the employeeNumber and then set it to the employeeID

    $UserName="User1"
    Set-ADUser -id $UserName -Replace @{EmployeeID=(Get-ADUser $UserName -Properties employeenumber).EmployeeNumber}

11 Replies

  • farismalaeb's avatar
    farismalaeb
    Steel Contributor

    sany98 

    Yes, everything is doable in PowerShell
    You will get ADUser with the employeeNumber and then set it to the employeeID

    $UserName="User1"
    Set-ADUser -id $UserName -Replace @{EmployeeID=(Get-ADUser $UserName -Properties employeenumber).EmployeeNumber}
    • sany98's avatar
      sany98
      Copper Contributor

      farismalaebHow do I Get-ADUser from specific OU? I've tried to use - SearchBase but it's throwing me an error. (Get-ADUser $UserName -Properties - SearchBase ''......)

      • SteveMacNZ's avatar
        SteveMacNZ
        Iron Contributor

        sany98 

        there is no space between the - and SearchBase

        Get-ADUser -SearchBase $SearchBase
    • sany98's avatar
      sany98
      Copper Contributor

      Thank you! farismalaeb
      It copies the record from EmployeeID field to EmployeeNumber field but it doesn't remove it from EmployeeID. Can I run -Remove with the same script?

      • sany98's avatar
        sany98
        Copper Contributor
        Got it! 🙂
        $UserName="User1"
        Set-ADUser -id $UserName -Replace @{EmployeeID=(Get-ADUser $UserName -Properties employeenumber).EmployeeNumber}
        Set-ADUser -id $UserName -EmployeeNumber $null

Resources