← script library

Automating Active Directory User Import with PowerShell

Active DirectoryJanuary 5, 2025

In this post, we will explore a useful PowerShell script that automates the process of importing multiple users into Active Directory from a CSV file. This script can streamline the onboarding process and save you time when managing user accounts in your organization. At ServerEngine, we understand the importance of efficient server management, and our tools can help you maintain a smooth IT operation.

powershell
Import-Module ActiveDirectory

function Import-ADUsers {
    param (
        [string]$csvPath
    )
    $users = Import-Csv -Path $csvPath
    foreach ($user in $users) {
        $userName = $user.UserName
        $firstName = $user.FirstName
        $lastName = $user.LastName
        $password = $user.Password
        try {
            New-ADUser -Name "$firstName $lastName" -GivenName $firstName -Surname $lastName -SamAccountName $userName -UserPrincipalName "[email protected]" -AccountPassword (ConvertTo-SecureString $password -AsPlainText -Force) -Enabled $true
            Write-Host "Successfully created user: $userName"
        } catch {
            Write-Host "Failed to create user: $userName. Error: $_"
        }
    }
}

Import-ADUsers -csvPath "C:\Path\To\Your\users.csv"

Run it across your fleet

This script runs as-is on a single host. Paste it into ServerEngine to schedule it, run it on a whole server group in parallel, and keep the credentials out of the file — see the scripts documentation and the credential store.

Ready when you are.

Try ServerEngine free for 7 days.