• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 257
  • Last Modified:

Generate AD Logins from SQL Table

I need to create an import/export process that generates Active Directory user accounts and mail contacts from information that is currently stored in a SQL server table.  I would prefer to use Powershell or T-SQL, as those are the scripting languages I am most familiar with.  I would like to get feedback on what the best approach to do this would be.  I would like to run the job(s) on a nightly basis and include checks that ignored pre-existing accounts and such.
1 Solution
Barry CunneyCommented:
Use powershell to connect to your database and get the SQL Server contact records into a powershell table object
Then iterate through each row in the table object and call the Add AD Member cmdlet substituting in the table fields - you will have to work out the index of the fields from SQL server - like maybe your first field(index 0) is the username etc.

$conn = New-Object Data.Sqlclient.Sqlconnection`
    ("Data Source=YOURDATABASE;Initial Catalog=Contact_Database;Integrated Security=SSPI;")
$adapter = New-Object Data.Sqlclient.Sqldataadapter("exec usp_GetUserDetails", $conn)
$set = new-object data.dataset
$table = new-object data.datatable
$table = $set.tables[0]

foreach ($Row in $table.Rows)
  Add-QADGroupMember -identity $Row[0] -Member $Row[1]....................... ;`
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

We Need Your Input!

WatchGuard is currently running a beta program for our new macOS Host Sensor for our Threat Detection and Response service. We're looking for more macOS users to help provide insight and feedback to help us make the product even better. Please sign up for our beta program today!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now