How to get users from windows server -local user accounts

  • can sql server get to - local user accounts ??

    i wont to get all the users and the local groups from  Windows Server

    in my Server (Doamin)

    and insert to new table in sql server

    thnks

  • you cannot get domain group members by using t-sql that I aware of.

  • and if i am The ADMINISTRATOR ???

  • Are you using AD ?

    if Yes create a linked server and then interrogate it :

    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/adsi/adsi/distributed_query.asp

    If no

    Then run:

    create table #t1 (data varchar(255))

    insert into #t1 exec master..xp_cmdshell 'net user'

    select  -- this parsing is just as a demo purpose you may need to change it for your own case   

           Left(data, charindex(' ', data, 1)) FirstCol,

           Substring(data,26,charindex(' ', data, 26)- 25) SecondCol,

           Substring(data,51,charindex(' ', data, 51) - 50) ThirdCol

    from #t1

    where data is not null

          and data not like '%\\%'

          and data not like 'The command completed successfully.%'

          and data not like '-----------------%'

    drop table #t1

     


    * Noel

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply