Active Directory via T-SQL (MS SQL Server 2005/2008)


Register ADL


See ADL.pdf

Initialize


DECLARE @domain SYSNAME, @user SYSNAME

EXEC MASTER..xp_regread @rootkey = N'HKEY_LOCAL_MACHINE',
     @key = N'SYSTEM\ControlSet001\Services\Tcpip\Parameters\',
     @value_name = N'Domain',
     @value = @domain OUTPUT

SET @user = N'dvolodin'

Work


-- Get domain users
SELECT * FROM vp_GetUsers(@domain)

-- Get user properties
SELECT * FROM  vp_GetUserProperties (@domain, @user)

-- Get domain groups
SELECT * FROM vp_GetGroups(@domain)

-- Get domain users in group
SELECT * FROM vp_GetUsersInGroup(@domain, N'Domain Admins')

-- Get domain groups in user
SELECT * FROM vp_GetGroupsInUser(@domain, @user)

--Set Active Directory property value
EXEC SetADProperty @domain, N'Administrator', '*******', N'mailNickname', N'newvalue'

Last edited Oct 5, 2010 at 1:03 PM by voldanmsu, version 24