Hash table with new user

Hi Powershell experts :slight_smile:

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.

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

New-ADUser @NewUserParams

Online help: https://msdn.microsoft.com/en-us/powershell/reference/5.0/microsoft.powershell.core/about/about_splatting

ah, yes… :slight_smile:

thanks