I wanted to create a script to create a User through it in Active Directory. I already created a one-liner, which creates the User correctly. But know I want the script to create a User with different inputs.
I created the code, but somehow it doesn't work, can anybody elaborate what I did wrong?
$name=$args[0]
$givenname=$args[1]
$surname=$args[2]
$userlogin=$args[3]
$loginold=$args[4]
$description=$args[5]
$phone=$args[6]
$mail=$args[7]
$password=$args[8]
$passwordexpire=$args[9]
$locked=$args[10]
$oupath=$args[11]
echo $name
echo $givenname
echo $surname
echo $userlogin
echo $loginold
echo $description
echo $phone
echo $mail
echo $password
echo $passwordexpire
echo $locked
echo $oupath
New-ADUser -Name $name -GivenName $givenname -Surname $surname -UserPrincipalName $userlogin -SamAccountName $loginold -description $description -OfficePhone $phone -EmailAddress $mail -AccountPassword (Read-Host -AsSecureString "AccountPassword") $password -PasswordNeverExpires $passwordexpire -Enabled $locked -path $oupath
pause
Error message:
New-ADUser : Cannot validate argument on parameter 'Name'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.
At C:\POwershell\Create_ad_user.ps1:27 char:18
+ New-ADUser -Name $name -GivenName $givenname -Surname $surname -UserPrincipalNam ...
+ ~~~~~
+ CategoryInfo : InvalidData: (:) [New-ADUser], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.ActiveDirectory.Management.Commands.NewADUser
Press Enter to continue...:
PS C:\Users\Administrator\Desktop>
echo $nameoutput something? Also,-AccountPassworddoesn't look right.$args