Note that there are some explanatory texts on larger screens.

plurals
  1. POCan not convert String to Secure String for use in New-ADUser
    text
    copied!<p>I'm using Primal Forms Community Edition to create a GUI that will stream line our new student creation process for our secretaries. In the lower level schools the students use their birthdays as their passwords so they're easy to remember. </p> <p>I have a Text Entry Box that is labeled as the "Birthday" Field. What I'm looking to do is take that field and use it for -AccountPassword in New-ADUser. However, no matter what I try I always get this error when trying to create a new user with my script. </p> <pre><code>New-ADUser : Cannot bind parameter 'AccountPassword'. Cannot convert the "System.Security.SecureString" value of type "System.String" to type "System.Security.SecureString". At C:\Users\pomeroyt\Google Drive\Work\Scripts\Powershell\student_creation_gui.ps1:377 char:12 + New-ADUser @User + ~~~~~ + CategoryInfo : InvalidArgument: (:) [New-ADUser], ParameterBindingException + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.ActiveDirectory.Management.Commands.NewADUser </code></pre> <p>The Code I'm using looks like this. </p> <pre><code>$password = $dob.text | ConvertTo-SecureString -AsPlainText -Force $user = @{ Description = "Student" UserPrincipalName = "$username@domain.local" Name = "$lname.text, $fname.text" SamAccountName = "$username" Surname = "$lname.text" GivenName = "$fname.text" EmailAddress = "$email" HomeDrive = H: HomeDirectory = "\\$server\Students\$yog\$username" ScriptPath = "$script" ChangePasswordAtLogon = 0 CannotChangePassword = 1 PasswordNeverExpires = 1 AccountPassword = "$password" Enabled = 1 Path = "OU=$yog,OU=$group,OU=STUDENTS,DC=domain,DC=local" } New-ADUser @User </code></pre> <p>I'm really at a loss here because everything I've seen says that what I'm doing should work</p> <p>Edit --</p> <p>The solution below did resolve the password issue. However, I didn't realize that I was actually seeing additional issues with my code. </p> <p>I turned on -verbose to see what was happening and discovered that the Name field was not outputting correctly. When putting "$lname, $fname" for Name = it resulted in the full output of $lname for some reason. I created a new string called $name and set it to = $lname.text+", "+$fname.text. </p> <p>Now Name = $name and the command fires as expected. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload