none
Set-Aduser is setting attribute name not its value RRS feed

  • Question

  • I am trying to set a custom attribute value using my existing attribute value. Its setting up the attribute name in my exntesion attribute not the value. Any guess. 

    Get-Aduser -identity XXX -properties EmployeeID |Set-Aduser -Add @{Extensionattribute1="$_.EmployeeID"}

    I know I am missing something very silly. Would appreciate any help.  


    • Edited by BLG Boy Thursday, November 3, 2016 6:26 PM
    Thursday, November 3, 2016 6:06 PM

Answers

  • Get-ADUser Vincent -Properties EmployeeID | Foreach {
            Set-ADUser -Identity $_ -Add @{Extensionattribute1 = "$($_.EmployeeID)"}
    }
    

    • Marked as answer by BLG Boy Thursday, November 3, 2016 6:55 PM
    Thursday, November 3, 2016 6:41 PM

All replies

  • Don't quote $_.employeeID.

    Richard Mueller - MVP Enterprise Mobility (Identity and Access)

    Thursday, November 3, 2016 6:38 PM
    Moderator
  • Get-ADUser Vincent -Properties EmployeeID | Foreach {
            Set-ADUser -Identity $_ -Add @{Extensionattribute1 = "$($_.EmployeeID)"}
    }
    

    • Marked as answer by BLG Boy Thursday, November 3, 2016 6:55 PM
    Thursday, November 3, 2016 6:41 PM
  • Get-Aduser -identity XXX -properties EmployeeID |%{Set-Aduser -Add @{Extensionattribute1=$_.EmployeeID}}

    You need to enumerate the results and not use quotes.


    \_(ツ)_/

    Thursday, November 3, 2016 6:51 PM
  • Thanks Richard, It works, I didnt thought I would have to use foreach for a single user as well. I am really not sure why we need to use it. 
    Thursday, November 3, 2016 7:07 PM
  • Best to not use quotes and % is the same as ForEach-Object.


    \_(ツ)_/


    • Edited by jrv Thursday, November 3, 2016 7:14 PM
    Thursday, November 3, 2016 7:12 PM
  • ...which is the same as ForEach-Object. I would encourage spelling out the entire cmdlet name - ForEach-Object - to avoid confusion.

    -- Bill Stewart [Bill_Stewart]

    Thursday, November 3, 2016 7:13 PM
    Moderator
  • ...which is the same as ForEach-Object. I would encourage spelling out the entire cmdlet name - ForEach-Object - to avoid confusion.

    -- Bill Stewart [Bill_Stewart]


    Yes - I agree.

    \_(ツ)_/

    Thursday, November 3, 2016 7:14 PM