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.
LVL 1
marrjAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
$adapter.fill($set)
$table = new-object data.datatable
$table = $set.tables[0]


foreach ($Row in $table.Rows)
{
  Add-QADGroupMember -identity $Row[0] -Member $Row[1]....................... ;`
}
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.