Posted On September 4, 2020

How to Add Domain Admins to SQL Server

kimconnect 6 comments
blog.KimConnect.com >> Codes , Database >> How to Add Domain Admins to SQL Server
Step 1:

Right-click Start > Search > type in ‘ssms.exe’ > right-click Microsoft SQL Server Management Studio > Run as Administrator

Authenticate using an sa account > New Query > paste this line:

/* Adding Principle into SQL sysadmin role */
exec sp_addsrvrolemember 'whatDomain\Domain Admins', 'sysadmin';
go

Observe a result similar to this:

Commands completed successfully.
Completion time: 2012-09-03T18:42:58.1788611-07:00

That’s it. There is no ‘Step 2.’ Fin.

# Alternative Method via PowerShell
$sa='sa'
$saPassword='whatpassword'
$domainAdmins="$env:USERDOMAIN\Domain Admins"

import-module sqlps
try{
    if($sa -and $saPassword){
        invoke-sqlcmd -username $sa -password $saPassword -Query "exec sp_addsrvrolemember '$domainAdmins', 'sysadmin'"
    }else{
        invoke-sqlcmd -Query "exec sp_addsrvrolemember '$domainAdmins', 'sysadmin'"
    }
}catch{
    write-warning $_
}

Alternative Graphical Interface Method:

Run Microsoft SQL Server Management Studio (ssms.exe) > authenticate as an sa > navigate to [Server Named Instance] > Security > right-click Logins > New Logins > set Login Name = YOURDOMAIN\Domain Admins & select ‘Windows authentication’

Click on Server Roles > put a check mark next to ‘sysadmin’ > click OK

Visually verify that ‘Domain Admins’ has been added to the security group

Troubleshooting:
Issue:

A member of the Domain Admins group could not logon to SQL Server even though such group has been granted the ‘sysadmin’ role on such database machine.

Resolution:

By default, Windows User Access Control (UAC) will associate the run-time of an un-elevated instance of SQL Server Management Studio in the context of a regular user, not ‘BUILTIN\Administrators’. To ensure that the GUI is initiated in the Admin contexts, one must right-click SSMS > select Run as Administrator. On then would members of the Domain Admins be granted access.

6 thoughts on “How to Add Domain Admins to SQL Server”

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Post

PowerShell: Creating VSS Snapshots on Microsoft File Server Clusters

<# VSS-Snapshots-on-Microsoft-File-Server-Clusters_v0.0.1.ps1 # Author: KimConnect.com Functions: 1. Create snapshots of all volumes on a file…

SQL Failover (Simple Method)

$servers="SQL01","SQL02","SQL03"; # Dynamic Credential method 1 $who = whoami if ($who.substring($who.length-2, 2) -eq "-admin"){$username=$who;} else…

Basic CSS: Override Class Declarations by Styling ID Attributes

<style>body {background-color: black;font-family: monospace;color: green;}.pink-text {color: pink;}.blue-text {color: blue;}</style><h1 class="pink-text blue-text">Hello World!</h1>