Service account details of named instances.

  • I want to get the service account details for SQL Server instances on the machine and add them to sysadmin. I tried to use the below logic. It works only if i know the INSTANCENAME value. I don't know how many instances are installed and what names. I want capture all the instance names available and run the below logic.

    DECLARE @ServiceaccountName varchar(250)

    EXECUTE master.dbo.xp_instance_regread

    N'HKEY_LOCAL_MACHINE', N'SYSTEM\CurrentControlSet\Services\INSTANCENAME',

    N'ObjectName',@ServiceAccountName OUTPUT, N'no_output'

    EXEC sp_addsrvrolemember @ServiceaccountName, 'sysadmin'

    Can someone please help me with modifying the logic.

    Thanks in advance.

  • Run this to get number of instances and names in a particular server

    Exec xp_regenumvalues N'HKEY_LOCAL_MACHINE',N'SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL'

    Ryan
    //All our dreams can come true, if we have the courage to pursue them//

  • Thanks, but sorry i am not confortable with T-SQL coding. Can you please show me how to write the looping logic.

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

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