Hash table with new user

This topic contains 3 replies, has 2 voices, and was last updated by  Albert van Boerum 1 year, 4 months ago.

  • Author
  • #65209

    Albert van Boerum

    Hi Powershell experts 🙂

    I'm stuck in a little basic code. I want to create a nice script for creating users but I get lost in a hash table.

    Lets break it down to a single line of code. The original code is longer but I think this is the problem:

    The following code works fine:

     new-aduser test001 

    I would expect this to work also:

    $NewUserParams = @{
    	Name ='test001'
    New-ADUser $NewUserParams

    The result I get when I run this is:

    New-ADUser : The name provided is not a properly formed account name
    At line:5 char:1
    + New-ADUser $NewUserParams
    + ~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (CN=System.Colle...etterwoon,DC=nl:String) [New-ADUser], ADException
        + FullyQualifiedErrorId : ActiveDirectoryServer:1315,Microsoft.ActiveDirectory.Management.Commands.NewADUser

    After half a day on the internet I hope someone can help me :-/
    Probably something easy but I cannot seem to get it. p.s. never worked with a hash before.

  • #65224

    Daniel Krebs

    If you change the dollar-sign of the hashtable variable into an @ it should work.

    New-ADUser @NewUserParams

  • #65226

    Daniel Krebs
  • #65257

    Albert van Boerum

    ah, yes... 🙂


You must be logged in to reply to this topic.