Use Data Stored in a SQL Server Database to Create Active Directory User Accounts with PowerShell

I need a few Active Directory users created in my test environment so I thought why come up with fake information when I could use information that I already have in a SQL Server database? The Employees table in the Northwind database looks like an easy enough candidate since all the data I need is in one table. This is about the concept and not about seeing how complicated I can make this process. Here’s the type of information I’ll pull out of this database to use for the Active Directory user accounts:

Here’s the PowerShell script to create the AD Users based on what’s in the Employee table in the Northwind SQL Server database. I’m running SQL Server 2012 which uses a PowerShell module. The same thing can be accomplished with SQL Server 2008 R2, but it uses a PowerShell Snap-in.

Let’s validate the first user listed above in Active Directory:

The Get-ADUser PowerShell cmdlet is what I call “pre-filtered”. You can see in the previous screenshot that the property count is 10, so what happened to all the other properties I set? In order to see all of the properties, you have to use the -properties parameter and specify an “*”:

As you can see there are a ton of properties. Let’s select only the ones we set when creating the user account:

Now anytime I need some test Active Directory users created, I can create the Northwind ones in less than a second:


Leave a Reply

%d bloggers like this: