Creating a group Managed Service Account (gMSA) on Windows
Create, authorize, install and use an Active Directory group Managed Service Account for a Windows service.
A group Managed Service Account (gMSA) is an Active Directory account whose password is generated and renewed automatically by Active Directory. A Windows service can authenticate with it without anyone entering or storing a password.
Prerequisites
- The domain must have a KDS root key (check with
Get-KdsRootKey). - The ActiveDirectory module must be available (RSAT or an AD server).
- The creation commands must be run with sufficient rights in Active Directory.
1. Create the account
Import-Module ActiveDirectory
New-ADServiceAccount -Name msa_appsvc -DNSHostName appsvc.example.com -Enabled $true
The account name starts with msa_ (a naming convention used here). The account is created automatically in the "Managed Service Accounts" OU.
2. Authorize the target machine
Add-ADComputerServiceAccount -Identity appserver01 -ServiceAccount msa_appsvc
Set-ADServiceAccount -Identity msa_appsvc -PrincipalsAllowedToRetrieveManagedPassword appserver01$
The first command associates the account with the machine. The second allows that machine to retrieve the account password. The machine name followed by $ identifies its computer account.
3. Install the account on the target machine
Run the command on the target machine, with local administrator rights:
Install-ADServiceAccount -Identity msa_appsvc
The original notes start PowerShell as LocalSystem with PsExec (psexec.exe -i -s powershell.exe). This step is not required when the session already has administrator rights.
4. Use the account in a service
In the Windows service properties (Log On tab):
| Field | Value |
|---|---|
| Account | EXAMPLE\msa_appsvc$ (the name ends with $, added automatically) |
| Password | Leave empty |
5. List and remove the account
Get-ADServiceAccount -Filter * -Properties * | Format-Table SamAccountName,LastLogonDate
Remove-ADComputerServiceAccount -Identity appserver01 -ServiceAccount msa_appsvc
Remove-ADServiceAccount -Identity msa_appsvc
Notes
- Remove the association with the machine first (
Remove-ADComputerServiceAccount), then delete the account. - Microsoft documentation: Group Managed Service Accounts overview.