The following example shows how to set up users in the Active Directory whose name is saved in a SQL-database with the help of PowerShell.
The result of the bulk import will then be sent via mail.
The script could for example create new AD-accounts from an HR database once per night.
I intentionally designed the script simple to make its functions clearly visible.
Requirements for the execution are:
- Powershell since version 2.0 (no ‘special modules‘ needed)
- Access to database
- Permission to create AD user objects in the specified user-container
Script: Bulk import AD users from SQL server table
Here is the PowerShell script with comments on how to do a mass import of Active Directory users from SQL server tables:
In this example the user is only set up with the necessary attributes ‘samAccountName’ and ‘cn’. The result is a deactivated user account without password.
In case further properties from a database should be used, the following changes are necessary:
You are directly accessing and writing to the Active Directory!
Therefore the script should be tested carefully before you are using it in a productive environment.
The author does not assume liability for loss of data, unwanted side effects or other guarantees.
The operator himself carriers the full risk from use or service of the script.
- Powershell AD SQL Mail