Newbie and need a little help copying custom attribute data over to another

This topic contains 4 replies, has 4 voices, and was last updated by Profile photo of The PowerShell Bear The PowerShell Bear 1 month, 2 weeks ago.

  • Author
    Posts
  • #63982
    Profile photo of Kelly Farrell
    Kelly Farrell
    Participant

    I have 2 custom attributes called saConcurID and another saSkillportid and I want saConcurID = saSkillportid and this is what I have but it doesn't like it. Set-ADUser : A parameter cannot be found that matches parameter name 'Idenity'.

    Import-Module ActiveDirectory – ErrorAction stop

    $users = Get-ADUser -SearchBase "OU=blah,OU=blah,OU=blah,DC=blah,DC=blah,DC=com" -filter * -properties cn, saconcurid, saskillportid| Select-Object cn, saconcurid, saskillportid

    foreach ($user in $users) {

    Set-ADUser -Idenity $user -Replace @{saconcurid = "$($_.saskillportid)"}
    }

  • #63994
    Profile photo of Daniel Krebs
    Daniel Krebs
    Participant

    Typo! Idenity should be Identity. You can also us the pipeline to pass in the user.

    $user | Set-ADUser -Replace @{saconcurid = $user.saskillportid}

    • #64003
      Profile photo of Kelly Farrell
      Kelly Farrell
      Participant

      it was only a typo here I typed it correct in my script but I will try your suggestion, thanks

      I just tried that and get set-ADUser : Object reference not set to an instance of an object

  • #64048
    Profile photo of Aapeli Hietikko
    Aapeli Hietikko
    Participant

    Hi,

    I'm not verifying your script more than fix the $users statement.

    $users = Get-ADUser -SearchBase "OU=blah,OU=blah,OU=blah,DC=blah,DC=blah,DC=com" -filter * -properties cn, saconcurid, saskillportid| Select-Object cn, saconcurid, saskillportid

    to

    $users = Get-ADUser -SearchBase "OU=blah,OU=blah,OU=blah,DC=blah,DC=blah,DC=com" -filter * -properties cn, saconcurid, saskillportid

    Your select-object kills the ad-object object type. Old school mistake which I run from time to time when getting only the output I want, just to see that it kills the script.

    • #64057
      Profile photo of The PowerShell Bear
      The PowerShell Bear
      Participant

      If there's a performance concern (one reason to trim output, if you're dealing with a large number of users), you could leave the select statement, but add "samaccountname". Then, specify the samaccountname property for your identity:

      $users = Get-ADUser -SearchBase "OU=blah,OU=blah,OU=blah,DC=blah,DC=blah,DC=com" -filter * -properties cn, saconcurid, saskillportid| Select-Object cn, saconcurid, saskillportid, samaccountname
      
      foreach ($user in $users) {
      
      Set-ADUser -Idenity $user.samaccountname -Replace @{saconcurid = "$($_.saskillportid)"}
      }
      

      Either way works; if there isn't a performance issue you're trying to overcome, though, I'd just leave Select-Object out. Get-ADUser already returns a limited set of properties by default.

You must be logged in to reply to this topic.