TSF – Giải pháp IT toàn diện cho doanh nghiệp SMB | HCM

P10 - Bulk User Creation in Active Directory Using PowerShell

📘 WinServer2025 – P10: Bulk User Creation in Active Directory Using PowerShell

In enterprise environments, IT administrators frequently need to create dozens or even hundreds of user accounts at the same time. Performing this task manually through Active Directory Users and Computers is slow, error-prone, and not scalable.

That is why bulk user creation in Active Directory using PowerShell and CSV files is considered a professional, enterprise-grade approach. It allows administrators to automate user provisioning, reduce human error, and maintain consistent account configuration.

In Part 10 of the Windows Server 2025 series, this tutorial demonstrates a complete end-to-end workflow for bulk user creation using PowerShell, based on a realistic enterprise lab scenario.


👥 Why Bulk User Creation Matters

As organizations grow, user onboarding becomes a recurring operational task. Manual user creation introduces several problems:

❌ Time-consuming repetitive work
❌ Inconsistent naming and attributes
❌ Higher risk of configuration errors
❌ Poor scalability

💡 PowerShell combined with CSV input provides the most efficient and maintainable solution for Active Directory automation.

This approach is widely used in enterprise environments for onboarding, migrations, and system integrations.


🧩 Lab Overview

This demo covers the full automation workflow:

📄 Preparing user data in Excel
🧹 Cleaning Vietnamese names to ensure consistency
✂️ Splitting first name and last/middle name correctly
📁 Preparing the CSV file and PowerShell script
⚙️ Performing bulk user creation in Active Directory

Each step is designed to ensure clean data and reliable automation.


🔧 Step 1: Remove Name Separators (Vietnamese Names)

Vietnamese names often contain inconsistent spacing or hidden separators. These issues can break automation scripts if not handled correctly.

🧹 Clean Name Data Using Unikey

1️⃣ Open the Excel file
2️⃣ Copy the column containing full names
3️⃣ Open Unikey → press Ctrl + Shift + F6
4️⃣ Select Unicode
5️⃣ Choose Remove separatorConvert encodingOK
6️⃣ Paste the cleaned result back into Excel

✅ Names are now standardized and safe for automation.


✂️ Step 2: Separate First Name and Last/Middle Name

Active Directory uses attributes such as GivenName and Surname, which require proper name separation.

📌 Extract First Name (Cell E2)

 
=TRIM(RIGHT(C2,LEN(C2)-FIND(“@”,SUBSTITUTE(C2,” “,”@”,LEN(C2)-LEN(SUBSTITUTE(C2,” “,””))))))
 

📌 Extract Last + Middle Name (Cell D2)

 
=LEFT(C3,LEN(C3)-LEN(E3))
 

🎯 This ensures accurate mapping for Active Directory attributes like GivenName and Surname.


📁 Step 3: Prepare Import Files

📄 CSV File Requirements

The CSV file contains all user data and must follow these rules:

  • Columns separated by TAB

  • Includes required fields such as:

    • Username

    • Password

    • Full Name

    • First Name

    • Last Name

    • Organizational Unit path

    • Enabled status

A clean CSV structure is essential for successful automation.


📜 PowerShell Script (PS1)

The following script handles CSV selection and user creation in Active Directory:

💻
filename.bash
Import-Module ActiveDirectory

[System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") | Out-Null

$dialog = New-Object System.Windows.Forms.OpenFileDialog
$dialog.Filter = "CSV (*.csv)| *.csv"
$dialog.ShowDialog() | Out-Null

$CSVFile = $dialog.FileName

if (!(Test-Path $CSVFile)) {
    Write-Host "File not found"
    exit
}

$CSV = Import-Csv -LiteralPath $CSVFile -Delimiter "`t"

foreach ($user in $CSV) {

    if ([string]::IsNullOrWhiteSpace($user.Username)) { continue }

    $SecurePassword = ConvertTo-SecureString ($user.Password.Trim()) -AsPlainText -Force

    New-ADUser `
        -Name $user.'Full Name' `
        -GivenName $user.'First Name' `
        -Surname $user.'Last Name' `
        -SamAccountName $user.Username `
        -UserPrincipalName "$($user.Username)@tsf.local" `
        -EmployeeID $user.'Employee ID' `
        -Description $user.Description `
        -Path $user.'Organizational Unit' `
        -AccountPassword $SecurePassword `
        -Enabled ([System.Convert]::ToBoolean($user.Enabled)) `
        -ChangePasswordAtLogon $false

    Write-Host "Created user: $($user.Username)"
}

Read-Host "Script complete. Press Enter to exit"

This script dynamically reads user data and provisions accounts directly in Active Directory.


▶️ Step 4: Run the PowerShell Script

To execute the automation:

1️⃣ Install LibreOffice (or use Excel)
2️⃣ Place the CSV and PS1 files in C:\ or any folder
3️⃣ Right-click the .ps1 file → Run with PowerShell
4️⃣ Select the CSV file when prompted
5️⃣ Wait for the script to complete and verify users in Active Directory

✅ Users are created automatically with consistent attributes.


🔐 Best Practices for Bulk User Creation

To ensure safe and reliable automation, always follow these best practices:

🛡️ Test scripts in a lab environment before production
📁 Use OU-based provisioning for better control
🔐 Avoid hardcoding passwords in scripts
📏 Apply least privilege principles for admin accounts

These practices reduce risk and improve long-term maintainability.


👨‍💻 Who This Tutorial Is For

This tutorial is ideal for:

👨‍💻 System Administrators
🧑‍🔧 IT Helpdesk engineers transitioning to system roles
🎓 Students learning Active Directory automation
🏢 IT teams managing large user environments

The focus is on real-world, production-ready automation.


🧩 Final Thoughts

Mastering bulk user creation in Active Directory using PowerShell is a critical skill for modern system administrators. Automation not only saves time but also ensures accuracy, consistency, and scalability.

By following this tutorial, you gain a reusable and professional provisioning workflow that can be adapted for onboarding, migrations, and enterprise operations on Windows Server 2025.

If you found this guide helpful, don’t forget to like, share, and subscribe for more real-world Windows Server and Active Directory tutorials 🚀

See also related articles

P19 – Safely Demote Domain Controller: Critical FSMO Guide

P19 – Safely Demote Domain Controller: Critical FSMO Guide https://youtu.be/vLgyzgmxzPI WinServer 2025 – P19 Demote Domain Controller Holding All FSMO Roles Demoting Domain Controller holding all FSMO roles is a critical operation in any Active Directory infrastructure. If done incorrectly, it can break authentication, replication, and domain services across the...

Read More

P18 – Critical Fix Guide Delete ADC Died Server 2025

P18 – Critical Fix Guide Delete ADC Died Server 2025 https://youtu.be/82fvirmHZ2k WinServer2025 – P18 Critical Fix Remove Dead ADC from Active Directory (Server 2025) When an Additional Domain Controller (ADC) fails permanently, leaving it inside Active Directory can cause serious long-term issues. Replication errors, DNS conflicts, GC problems, and even...

Read More

P17 – Critical Guide Delete PDC Died in Server 2025

P17 – Critical Guide Delete PDC Died in Server 2025 https://youtu.be/ipF1EziL_C8 WinServer2025 – P17 How to Remove a Failed Domain Controller in Windows Server 2025 When a Primary Domain Controller (PDC) fails permanently and cannot be brought back online, simply shutting it down is not enough. The failed controller still...

Read More
💬 TSF Chat Box
Customer Services
Chăm sóc khách hàng