Reputation: 87
So I am currently in the process of teaching myself PowerShell on a test domain with the help of a few guides. After picking up a bit I'm working on a project to create users in AD from first and last names in a CSV. The only thing I cannot get working is for it to require the password to be changed at logon, I'm getting no errors, and the entries are being created, but the box in the user's account options is not ticked.
import-csv users.csv |
select Surname,
@{n='GivenName';e={$_.'FirstName'}},
@{n='samaccountname';e={$_.FirstName.substring(0,2) + $_.Surname}},
@{n='UserPrincipalName';e={$_.FirstName.substring(0,2) + $_.Surname}},
@{n='Name';e={$_.'FirstName' + ' ' + $_.'Surname'}} |
New-ADUser -AccountPassword (ConvertTo-SecureString -AsPlainText "Password1" -Force) -ChangePasswordAtLogon $true -Path "OU=Intake 20XX,OU=Students,OU=Ravenloft users,DC=RAVENLOFT,DC=test"
Edit- With a bit more investigation, I believe that it may not be creating a password at all, as the accounts are disabled. However the password "Password1" that I have used in the script does meet the requirements as when creating one in AD manually with this password, it works fine. So how can I progress from this issue?
Upvotes: 1
Views: 1598
Reputation: 825
Use the -enabled $True switch for New-ADUser, so the full command for the last line would be...
New-ADUser -Enabled $true -AccountPassword (ConvertTo-SecureString -AsPlainText "Password1" -Force) -ChangePasswordAtLogon $true -Path "OU=Intake 20XX,OU=Students,OU=Ravenloft users,DC=RAVENLOFT,DC=test"
Upvotes: 1