PowerShell

Create Multiple Active Directory Users with PowerShell

There was a need to create a large number of users in Active Directory and what better way to achieve such a goal than to use PowerShell?!

Simply create your CSV file with your desired headers as per below image (you can of course add more headers to suit your needs, just make sure they reflect in the script):

And execute the following in PowerShell ISE:

$csv = Import-Csv -Path "C:\Scripts\users.csv"

ForEach ($item In $csv) 
    { 
$pwdLength = 15
$noNonAlphaChar = 5
$pw = [Web.Security.Membership]::GeneratePassword($pwdLength,$noNonAlphaChar)
$spw = ConvertTo-SecureString -AsPlainText $pw -Force
        
        $create_user = New-ADUser -DisplayName $item.Name -Name $item.Name -SamAccountName $item.SAMName -AccountPassword $spw -Description $item.Description -Path $item.OU 
        Write-Output "User $($item.Name) with $pw created!"

    }

Note that the created accounts will be disabled. Additionally you might want to consider locking the accounts down to only log on to certain systems as well as having an expiring date and the user not being able to change the password – basically follow whatever policies the organisation has in place.

twitterredditpinterestlinkedinmail

Leave a Comment

Your email address will not be published. Required fields are marked *