-1
votes

I have a table in my SQL Server database which stores the users who have access to my application. Now, I want to move these users to an AD group.

One option is to create a hangfire job and move these users to AD group using LDAP queries. However, there are very less instances of new users being added.

Is there any way of moving a newly created user to AD group through SQL only? I'm trying to find a way of not using the hangfire job. Is this even possible?

So, is your problem a batch create of the old users or creating new users as and when needed ? - Caius Jard
Personally I would do this in Powershell. Is this going to be a one-off job? - Charlieface
What's the goal of moving the users out to Active Directory? Are you intending them to actually login and authenticate to SQL Server using those accounts via domain/Windows authentication? If so it sounds like a chicken-and-egg problem - how is a user going to get added to this table, and subsequently migrated to AD, if they don't already have an account in AD with which they connect to SQL Server? - AlwaysLearning
When I joined my current place of work, there was a prior employee who was xp_cmdshell happy, so unfortunately I was exposed to this nonsense quite a bit. You could theoretically accomplish this using a loop over your table records and xp_cmdshell calls that utilize calls powershell.exe to import your users. I would say this is possibly one of the worst solutions you could come up with, but I could write a demonstration if needed. - trenton-ftw