0

I am trying to create a AD user in my OU called public that has a username of numbers is enabled and a password set that is password1. When I run the command I get the error A positional Parameter cannot be found that accepts argument '$null'.

Any help would be appreciated

Here is what I put into powershell

`New-ADUser -Name "BoB Glen" -GivenName "BoB"-Surname "Glen" -DisplayName "2003487" $secpasswd = ConvertTo-SecureString -String "pa$$word1" -AsPlainText -Force -AccountPassword $secpsswd -Enabled $true -Path "OU=Public,DC=Company,DC=epl,DC=local"` 

Here is the entire error

New-ADUser : A positional parameter cannot be found that accepts argument '$null'. At line:1 char:1 + New-ADUser -Name "Adam Bandola" -GivenName "Adam" -Surname "Bandola" ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [New-ADUser], ParameterBindingException + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.ActiveDirectory.Management.Commands.NewADUser 

1 Answer 1

1

Ok so lets break apart whats happening :

New-ADUser -Name "BoB Glen" -GivenName "BoB"-Surname "Glen" -DisplayName "2003487" $secpasswd = ConvertTo-SecureString -String "pa$$word1" -AsPlainText -Force -AccountPassword $secpsswd -Enabled $true -Path "OU=Public,DC=Company,DC=epl,DC=local" 

The symbol ` is a escape character in powershell. An example of how to use it would be :

write-output " `" " 

this would output : " instead of the and error : missing the terminator which would be thrown is I did " " ". you can also use it to split long commands into multiable lines like

Get-Alias` -name "%" 

In the Command you are trying to use a -whatever is a parameter and the very next thing after it as the value you are submitting to that parameter

-parameter Value 

Also in powershell the $ is a variable.

$Hello = "World" 

The current issue you are having is you are calling a command and then try to create a variable in the middle of the command, as well as starting the command with a escape key and ending it with a escape key (unless its part of a larger command that you are splitting into new lines)

You can surround a value with parentheses like : (new command here)

A working command would look like this :

New-ADUser -Name "BoB Glen" -GivenName "BoB"-Surname "Glen" -DisplayName "2003487"` -AccountPassword (ConvertTo-SecureString -String 'pa$$word1' -AsPlainText -Force)` -Enabled $true -Path "OU=Public,DC=Company,DC=epl,DC=local" 

You will notice that the variable $secpasswd is removed, the command ConvertTo-SecureString is inside parenthesis () the first and last escape characters ` removed, added escape characters to new lines in the command to make it visually more understandable and finally put single quotes around the word pa$$word because double quotes will try and read $ as a variable, while single quotes are read literally.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.