After creating the KDC keys in your Active Directory we can continue with where it all is about: creating the GMSA.

Before we will create the account, we first need to create a group. This group will hold all of the computeraccounts of the servers which run the services with the gMSA acccounts.

It is a good practice to follow your conventions. These conventions will merely hold naming conventions, place where your group will reside and supportable items.

In my case, I will just create a group named “” This is the group which will hold all the SQL Server computeracounts . It will be managed by my “”. In this group my DBA’s are added.

I will use the following command:

New-ADGroup -Name “” -SamAccountName “” -GroupCategory Security -GroupScope Global -DisplayName “Group used by GMSA for SQL Server” -Path “CN=Groups,DC=MaroliCIT,DC=Intra” -Description “Members of this group have the SQL servers role with a GMSA account ” -ManagedBy “”

You can check the group by using the get-adgroup command.

Now the group has been created and verified, the most important part of gMSA is there, we need to create the account. I will use the name “Maroli.SQL2016DE” for this.  

New-ADServiceAccount “Maroli.SQL2016DE” -DNSHostName “Maroliict.intra”
-PrincipalsAllowedToRetrieveManagedPassword “”
-KerberosEncryptionType RC4, AES128, AES256 -TrustedForDelegation $true

This sets up the Group Managed Service accounts. But with GMSA in place, you can also add Service Principal Names for your servers. Therefore you need to modify the read and write to Service Principal Names. Therefore we can do this manual, but hey,

We are automating the stuff

So this means we need to be able to reproduce that. Therefore I have borrowed some code of my colleagues from Active Directory Management. That piece of code is down here:

# ===================== Functions =========================================================
Function Set-SpnPermission {

if(!$write -and !$read){
   throw “Missing either -read or -write”

$rootDSE = [adsi]”LDAP://RootDSE”
$schemaDN = $[“schemaNamingContext”][0]
$spnDN = “LDAP://CN=Service-Principal-Name,$schemaDN”
$spnEntry = [adsi]$spnDN
$spnSecGuid = new-object GUID $guidArg
if($read ){


if($write -and $read){

$accessRuleArgs = $identity,$adRight,”Allow”,$spnSecGuid,”None”
$spnAce = new-object DirectoryServices.ActiveDirectoryAccessRule $accessRuleArgs$TargetObject.psbase.ObjectSecurity.AddAccessRule($spnAce)
return $spnAce

Below are the command that we used to get the proper values and to combine the function and standard AD functions to a gMSA account which creates the SPN’s:

# ======================= Request the gMSA properities ============================================

$groupObj = Get-ADServiceAccount $gMsaSvcAccountName   -Properties ManagedBy -server $Domain
#$groupObj = get-adgroup -Identity $RetrieveMgmtPasswd #RetrieveMgmtPasswd
$acl = ($groupObj.DistinguishedName)  #group
$TargetObject = “LDAP://$($acl)”
$Identity = [security.principal.ntaccount]”SELF”
Set-SpnPermission -TargetObject $TargetObject -Identity $Identity -write -read

This piece of code will do that trick. 

That was it for this time. Next time we talk about modifications to the installation of SQL and what we need to do before installation.