Hash table with new user

This topic contains 3 replies, has 2 voices, and was last updated by Profile photo of Albert van Boerum Albert van Boerum 3 months ago.

  • Author
    Posts
  • #65209
    Profile photo of Albert van Boerum
    Albert van Boerum
    Participant

    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
    Profile photo of Daniel Krebs
    Daniel Krebs
    Moderator

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

    New-ADUser @NewUserParams

  • #65226
    Profile photo of Daniel Krebs
    Daniel Krebs
    Moderator
  • #65257
    Profile photo of Albert van Boerum
    Albert van Boerum
    Participant

    ah, yes... 🙂

    thanks

You must be logged in to reply to this topic.