Bulk Creating Active Directory Users from an Excel File Using Python and PowerShell

Managing a large number of Active Directory users manually can be time-consuming and error-prone. In this guide, we will automate the process by generating a CSV file from an Excel spreadsheet using Python and then importing the users into Active Directory with PowerShell.

Before starting, make sure you have:

Install the required Python libraries:


Step 1: Prepare the Excel File

The worksheet should contain the following columns:

NameSamAccountNameUserPrincipalNamePasswordDomainEnabled
John Smithjsmithjsmith@omidgroup.localP@ssw0rd1omdgoup.localTRUE
Jane Doejdoejdoe@omidgroup.localS3cureP@ssomdgroup.localTRUE

Column Description

  • Name: Display name of the user.
  • SamAccountName: The logon name used for Windows authentication.
  • UserPrincipalName: User logon name in email format.
  • Password: Initial password assigned to the user.
  • Domain: The Active Directory domain name.
  • Enabled: Specifies whether the account should be enabled.

Step 2: Convert Excel to CSV Using Python

The following Python script reads the Excel file and creates a CSV file that can be imported by PowerShell.


Step 3: Import Users into Active Directory

This script performs the following actions:

  1. Imports the CSV file.
  2. Converts the plain text password into a secure string.
  3. Creates a new Active Directory user.
  4. Enables the account.
  5. Forces the user to change the password at first logon.

Running the Script

Copy both files to your Domain Controller or management server:

Then run:


Benefits of This Method

  • Saves time when creating multiple users.
  • Reduces manual configuration errors.
  • Easily reusable for onboarding new employees.
  • Can be extended to include Organizational Units (OUs), groups, departments, and additional user attributes.

By combining Python and PowerShell, administrators can quickly automate bulk user provisioning in Active Directory with minimal effort.

Leave a Comment

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

Scroll to Top