Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

How can I create a domain user account and set the default password in PowerShell from a CSV?

Note that I know how to do this, I'm writing this as a self-answered question to share this knowledge. If anyone has a better answer, please chime in!

share|improve this question

1 Answer 1

up vote 2 down vote accepted

This answer assumes that you have a CSV with two columns that have the headings: username and password.

It doesn't take make other attributes, such as firstname, lastname, manager, department, etc. They can all be added and are outlined in the get-help new-aduser -full command.

This is the bare minimum that needs to be done to automate account creation. In production, you'll probably want to force password change on first logon as well as setting many other attributes.

Import-Module ActiveDirectory

Import-CSV c:\users\marra\desktop\userlist.csv | ForEach-Object {
    $name = $_.username                                               
    $pw = $_.password 
    $ss = ConvertTo-SecureString -string $pw -asPlainText -force        

    New-ADUser $name -SamAccountName $name -AccountPassword $ss -Path "OU=MyUserOU,DC=mydomain,dc=com" -Enabled $TRUE        
    }
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.