create login with sysadmin and add to local server admin group

  • Need script for below.

    1)Add the user ''AD\abc' to local admin group in server.

    2)Create login 'AD\abc' and Grant sysadmin access for AD\abc

    Any help Please ...

  • Two seconds in Google would have given you the answer.

    However...

    To add a user to a the local administrators group:

    net localgroup Administrators AD\abc /add

    To create a windows login and grant sysadmin privileges:

    CREATE LOGIN [AD\abc] FROM WINDOWS;

    ALTER SERVER ROLE sysadmin ADD MEMBER [AD\abc];

    -- Gianluca Sartori

  • thank you.

    Actually i need a sql script to add the user to local admin also.

  • charipg (4/30/2015)


    thank you.

    Actually i need a sql script to add the user to local admin also.

    xp_cmdShell for the commandline script already provided, but i'd bet there is a 90% chance it will fail, since you have to be an administrator to add an administrator, and the Service Account running SQL probably is not a local admin(and should not be, either)

    administration of users for the operating system is a function that should always be handled outside of SQL, in my opinion.

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

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

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