none
Set-ADUser -Replace RRS feed

  • Question

  • Hi

    I could be wrong, but I think there's an error in the help for Set-ADUser, in the section describing the -Replace parameter:

    For example, if you want to replace the value "555-222-2222" with the values
    "555-222-1111" for Phone-Office-Other attribute (LDAP display name
    'otherTelephone') set the Replace parameter as follows.

    -Replace @{otherTelephone='555-222-2222', '555-222-1111'}

    Wouldn't that example set the otherTelephone property to the two values given rather than replacing the first one wuth the second?

    Thanks

    Saturday, December 28, 2013 10:46 PM

Answers

  • Correct...I just tested it and it does add two values.
    Let's see if someone else can also replicate this.

    Just a thought -- You can remove and then add the attribute as a workaround.


    Knowledge is Power{Shell}.

    • Marked as answer by stromnessian Sunday, December 29, 2013 10:05 AM
    Sunday, December 29, 2013 4:07 AM
  • Based on my testing, the -Replace parameter with two values ensures both values are added. It does not replace one value with the other value. I would recommend you open a case with connect.microsoft.com. I have tested this on both PowerShell 2.0 on Server 2008 R2 and PowerShell 3.0 on Win7 x64 SP1.
    • Marked as answer by stromnessian Sunday, December 29, 2013 10:05 AM
    Sunday, December 29, 2013 4:17 AM
  • Looks like you're right. I just took a look through the AD cmdlets with dotPeek, and when the -Replace parameter is used (with an array), it calls Clear() followed by AddRange() on the property collection:

    if (customPropertyValue is object[])
    {
        propertyValue.Clear();
        propertyValue.AddRange((object[]) customPropertyValue);
    }
    else
    {
        propertyValue.Value = customPropertyValue;
    }

    • Marked as answer by stromnessian Sunday, December 29, 2013 10:05 AM
    Sunday, December 29, 2013 4:20 AM

All replies

  • Correct...I just tested it and it does add two values.
    Let's see if someone else can also replicate this.

    Just a thought -- You can remove and then add the attribute as a workaround.


    Knowledge is Power{Shell}.

    • Marked as answer by stromnessian Sunday, December 29, 2013 10:05 AM
    Sunday, December 29, 2013 4:07 AM
  • Based on my testing, the -Replace parameter with two values ensures both values are added. It does not replace one value with the other value. I would recommend you open a case with connect.microsoft.com. I have tested this on both PowerShell 2.0 on Server 2008 R2 and PowerShell 3.0 on Win7 x64 SP1.
    • Marked as answer by stromnessian Sunday, December 29, 2013 10:05 AM
    Sunday, December 29, 2013 4:17 AM
  • Looks like you're right. I just took a look through the AD cmdlets with dotPeek, and when the -Replace parameter is used (with an array), it calls Clear() followed by AddRange() on the property collection:

    if (customPropertyValue is object[])
    {
        propertyValue.Clear();
        propertyValue.AddRange((object[]) customPropertyValue);
    }
    else
    {
        propertyValue.Value = customPropertyValue;
    }

    • Marked as answer by stromnessian Sunday, December 29, 2013 10:05 AM
    Sunday, December 29, 2013 4:20 AM
  • Thanks for the answers.  I've submitted it to Microsoft.
    Sunday, December 29, 2013 10:07 AM