Forum Discussion

mmussolini's avatar
mmussolini
Copper Contributor
Nov 19, 2024

Powershell 7 getting error updating multi-valued attribute using Set-ADUser. PS 5.1 works

Hi there,

I recently moved to PS 7.4 since there is some additional commands related to parallel threads.

Now I'm facing an unexpected error due to multivalued updates using Arrays.

It says "Invalid type 'System.Collections.ArrayList'" using the following command (that works in previous PS versions):

Set-ADUser -identity "user" -Replace @{uid=@("value1","value2")}


Already tried many options, like using variable, explicit array declaration and followed Copilot suggestions, but no success yet.

It seems like a bug for me. Does anybody knows how to overcome this issue?

3 Replies

  • LainRobertson's avatar
    LainRobertson
    Silver Contributor

    Hi mmussolini ,

     

    I'm not seeing this error under 7.4.6 as shown below.

     

     

    Perhaps check you're using Microsoft's shipped module and not an alternative from the gallery. You can check as shown below, where the first-party module will reside under the Windows directory (as distinct from the Program Files directory if it's a gallery module installed per computer):

     

    (Get-Module -Name ActiveDirectory).Path;

     

     

    Another option is to load the Active Directory module first, using the UseWindowsPowerShell parameter as shown below, but strictly-speaking, this shouldn't be necessary - as demonstrated above.

     

    I'd still check the module's path to see if it's the first-party module from the correct location ahead of using this workaround should that not be the case.

     

    Import-Module -Name ActiveDirectory -UseWindowsPowerShell;

     

    Cheers,
    Lain

    • mmussolini's avatar
      mmussolini
      Copper Contributor

      Hi LainRobertson, thank you for your reply. 

      After many tests I realized that is something wrong with my Windows Server 2016 Powershell AD module (1.0), since I've tested the same version on W11 and everything works fine.

      So I've tried to put (manually) the same W11 AD Module version (1.0.1.0) in the WS2016 and somehow it got worse.

      May be it's a bug that shows up only in certain conditions?

      • LainRobertson's avatar
        LainRobertson
        Silver Contributor

        Hi mmussolini ,

         

        It may or may not be something to do with Server 2016 - I can't say for sure as I no longer have access to Server 2016.

         

        My gut feeling, however, is that it isn't an issue with the ActiveDirectory library, as the type mentioned in the error - System.Collections.ArrayList - is a type that is provided natively within .NET Core (which is what PowerShell uses, unlike Windows PowerShell, which uses .NET Framework).

         

        If you open up a new PowerShell session and run the following command, what do you get as the output?

         

        [System.Collections.ArrayList].Assembly;

         

        On PowerShell 7.4.6 on Windows 10 22H2, I get the following output, which confirms that the type exists as well as the version and path to the underpinning library.

         

        If you get an error (such as the one from your opening post), then your real root cause for the error is that something has gone wrong with your PowerShell installation.

         

         

        Cheers,
        Lain

Resources