Manachi Manachi - 1 month ago 7x
PowerShell Question

How to automatically populate Active Directory hashedPassword field using PowerShell

I'm working with a client who is attempting to import AD users via

. The following command is being used as an initial test:

New-ADUser -Name "John Smith" `
-SamAccountName Smithbor `
-GivenName John `
-Surname Smith `
-EmailAddress `
-Path 'OU=Users,DC=stackoverflow,DC=com' `
-ChangePasswordAtLogon $false `
-Enabled $true `
-AccountPassword (ConvertTo-SecureString -AsPlainText "foo12345678" -Force)

This appears to work, in that it correctly creates an AD user, however the
field is not being populated, and this
field is required for some further integration. Is there a way to automatically populate the
field at this stage?


Sometimes the password setting can fail due to password policy restrictions. You could try using Set-ADAccountPassword to set the password after the account has been created.

Set-ADAccountPassword -Identity username -Reset -NewPassword (ConvertTo-SecureString -AsPlainText "password" -Force)