Using managed service accounts (MSA and gMSA) in Active Directory

To use a managed service account in Active Directory, create a KDS root key once, create the account with New-ADServiceAccount, install it on the host with Install-ADServiceAccount, and set the service or task to log on as DOMAIN\name$ with no password.

This guide covers standalone MSAs, group MSAs (gMSA) and the delegated MSA (dMSA) in Windows Server 2025, plus running services and scheduled tasks under them and fixing the usual errors.

Create a group managed service account (gMSA) in Active Directory

A gMSA is the type to pick for almost any new service: Windows rotates its password, and it works on one server or many. Run these commands in an elevated PowerShell window with the Active Directory module, as a member of Domain Admins or Enterprise Admins.

  1. Create a security group, for example gMSA-WebHosts, and add the computer accounts of every server that will run the service.
  2. If the domain has no KDS root key yet, run Add-KdsRootKey -EffectiveImmediately on a domain controller and allow up to 10 hours for replication.
  3. Create the account: New-ADServiceAccount -Name gmsa-web -DNSHostName gmsa-web.contoso.com -PrincipalsAllowedToRetrieveManagedPassword gMSA-WebHosts.
  4. Restart each member server so it picks up its new group membership.
  5. On each member server, run Install-ADServiceAccount -Identity gmsa-web.
  6. Run Test-ADServiceAccount -Identity gmsa-web on the same server and check it returns True.
  7. Set the service or scheduled task to run as CONTOSO\gmsa-web$ with a blank password.

gMSA names must be unique across the whole forest, not just the domain. Keep the name at 15 characters or fewer so the SAM account name works with older systems; Windows appends the $ itself.

MSA vs gMSA vs dMSA vs virtual accounts

Windows Server offers four managed identities for services. They differ in how many servers can use them and who looks after the password.

Your situation Use this account type Why
One service on one domain-joined server Standalone MSA (sMSA) Linked to a single computer; Windows resets the password and handles SPNs
The same service on several servers, a web farm or a load balancer Group MSA (gMSA) Domain controllers compute the password and every authorised host retrieves it
Replacing an old user account used as a service account on Windows Server 2025 Delegated MSA (dMSA) Ties authentication to the device identity and disables the old account's password
A local service that only needs the computer's own network identity Virtual account (NT SERVICE\name) No password at all; network access uses DOMAIN\computer$
An application that supports none of the managed account types Ordinary domain user account Works anywhere, but you set and rotate the password yourself under the domain password policy

Passwords on ordinary user accounts are only as strong as the Active Directory password policy and the admin who rotates them, which is the main reason to move them to a gMSA or dMSA. Failover clusters themselves do not support gMSAs, but a Windows service, app pool or scheduled task running on top of the Cluster service can use one.

gMSA requirements in Active Directory

Requirement Detail
Domain and forest functional level Windows Server 2012 or later for gMSA support on all devices
KDS root key One per forest, created with Add-KdsRootKey; event ID 4004 in the KdsSvc Operational log confirms it
Permissions Domain Admins or Enterprise Admins, or delegated rights to create msDS-GroupManagedServiceAccount objects; Account Operators cannot by default
Management tools Active Directory module for Windows PowerShell (part of RSAT) and a 64-bit PowerShell session
Kerberos Registered SPNs for inbound services, working DNS, synchronised clocks and AES encryption support on the hosts
Host operating system Windows Server 2012 or later; gMSAs do not apply to earlier versions

If you manage AD from a workstation instead of a domain controller, install Active Directory Users and Computers and the rest of RSAT first, then run Import-Module ActiveDirectory.

Create the KDS root key with Add-KdsRootKey

Domain controllers need a Key Distribution Service root key before they can generate gMSA passwords. Create it once on a domain controller running Windows Server 2012 or later. Standalone MSAs do not need it.

Add-KdsRootKey -EffectiveImmediately

Adds a KDS root key that the local domain controller uses at once. Other domain controllers can use it only after replication, so gMSA creation waits up to 10 hours by design.

You should see: Event ID 4004 appears in the KdsSvc Operational log, and New-ADServiceAccount stops failing with a key error once the key has replicated.

In a lab with a single domain controller, Add-KdsRootKey -EffectiveTime ((get-date).addhours(-10)) backdates the key so you can create a gMSA straight away. Do not use the backdated key in production.

Avoid deleting and re-creating the root key. Domain controllers cache the old key, so restart the KDC on every domain controller if you ever have to re-create it.

How to create a managed service account (MSA) in Active Directory

A standalone MSA is restricted to one computer. It suits a single SQL Server or IIS instance that will never move to a second server.

  1. Open PowerShell as administrator on a computer with the Active Directory module.
  2. Run New-ADServiceAccount -Name svc-sql01 -RestrictToSingleComputer to create the account.
  3. Link it to its host with Add-ADComputerServiceAccount -Computer SRV01 -ServiceAccount svc-sql01.
  4. Sign in to SRV01 and run Install-ADServiceAccount -Identity svc-sql01.
  5. Run Test-ADServiceAccount -Identity svc-sql01 and check it returns True.

Without -Path, the account lands in the domain's Managed Service Accounts container. Linking the account to a computer and installing it locally are separate steps; both are needed.

For a server in a site with only read-only domain controllers, create the sMSA with a known password and install it with Install-ADServiceAccount -Identity svc-sql01 -PromptForPassword.

Install managed service account on Windows

Install the account locally on each host that runs the service. Installing checks the computer is allowed to use the account and sets up automatic password retrieval.

  1. On Windows Server, open Server Manager > Add roles and features, go to Features, expand Remote Server Administration Tools and select the Active Directory module for Windows PowerShell under the AD DS and AD LDS tools.
  2. On Windows 10 or Windows 11 Pro or Enterprise, open Settings > System > Optional features, select Add a feature, search for Remote and add RSAT: Active Directory Domain Services and Lightweight Directory Services Tools.
  3. Open PowerShell as administrator and run Import-Module ActiveDirectory.
  4. Run Install-ADServiceAccount -Identity gmsa-web.
  5. Run Test-ADServiceAccount -Identity gmsa-web to confirm the host can retrieve the password.

Install-ADServiceAccount fails for a gMSA unless the account's PrincipalsAllowedToRetrieveManagedPassword list includes this computer or a group it belongs to. It must run in an elevated session and does not work against a read-only domain controller.

Install managed service account tools: AD DS and AD LDS Tools in RSAT
Expand Remote Server Administration Tools, then Role Administration Tools, and tick AD DS and AD LDS Tools for the PowerShell module. (Image: Microsoft)

How to run a Windows service as a managed service account

Services set through the Service Control Manager accept an MSA or gMSA directly. The Services console is the quickest place to do it on a single server.

  1. Press Win + R, type services.msc and press Enter.
  2. Right-click the service and select Properties.
  3. Open the Log On tab and select This account.
  4. Type the account as CONTOSO\gmsa-web$, with the $ at the end.
  5. Clear the Password and Confirm password boxes so both are empty.
  6. Select OK; Windows grants the account the Log on as a service right if it does not have it.
  7. Right-click the service and select Restart.

The host fetches the password from a domain controller when the service starts. IIS application pools can use a gMSA the same way through IIS Manager; if Test Settings reports a bad password there, a running pool without 503 errors means the identity is fine.

Using managed service accounts (MSA and gMSA) in Active Directory
The gMSA name appears with its trailing $ once it holds this right, which Windows grants from the Log On tab. (Image: Microsoft)

Run Windows scheduled task with managed service account (gMSA)

Task Scheduler supports gMSAs, but the gMSA principal has to be set, and later changed, with the ScheduledTasks PowerShell cmdlets. You can still open Task Scheduler afterwards to check its history.

  1. Grant the gMSA the Log on as a batch job right on the server in Local Security Policy > Local Policies > User Rights Assignment, or through Group Policy.
  2. Create the action: $action = New-ScheduledTaskAction -Execute "powershell.exe" -Argument "-File C:\Scripts\cleanup.ps1".
  3. Create the trigger: $trigger = New-ScheduledTaskTrigger -Daily -At 3am.
  4. Create the principal: $principal = New-ScheduledTaskPrincipal -UserId "CONTOSO\gmsa-task$" -LogonType Password.
  5. Register the task: Register-ScheduledTask -TaskName "Nightly cleanup" -Action $action -Trigger $trigger -Principal $principal.
  6. Add the gMSA to any local group the job needs, such as Backup Operators, and nothing more.

-LogonType Password is the literal word Password, not a password. It tells Task Scheduler to retrieve the gMSA password from a domain controller each time the task runs.

Scheduled task with gMSA: Log on as a batch job in User Rights Assignment
Open User Rights Assignment under Local Policies in Group Policy and add the gMSA to Log on as a batch job. (Image: Microsoft)

How to check a gMSA with Test-ADServiceAccount

Two commands show whether a managed service account is ready: one on the host, one against Active Directory.

  1. On the host, run Test-ADServiceAccount -Identity gmsa-web; True means the computer can retrieve and use the password.
  2. If it returns False, run it again with -Verbose to see the reason.
  3. On any management machine, run Get-ADServiceAccount -Identity gmsa-web | Select-Object * and check PrincipalsAllowedToRetrieveManagedPassword, DNSHostName and ServicePrincipalNames.
  4. Check the service's Log On tab or the task's Run as account shows the name ending in $.

Add a server to an existing gMSA

Scaling a service out to another server means letting that server retrieve the gMSA password. Most properties change with Set-ADServiceAccount, but the password interval does not.

  1. If the gMSA uses a security group, add the new server's computer account to that group in Active Directory Users and Computers or with Add-ADGroupMember.
  2. If the gMSA lists computers directly, run Set-ADServiceAccount -Identity gmsa-web -PrincipalsAllowedToRetrieveManagedPassword SRV01$,SRV02$,SRV03$ with the full list.
  3. Restart the new server so its group membership updates.
  4. Run Install-ADServiceAccount -Identity gmsa-web on the new server.
  5. Run Test-ADServiceAccount -Identity gmsa-web and check for True.

The gMSA password changes every 30 days by default. To use a different interval, set -ManagedPasswordIntervalInDays when you create the account; it is read-only afterwards, so a new interval needs a new gMSA.

Uninstall and remove a managed service account

  1. Switch every service and task on the host to another account first.
  2. On the host, run Uninstall-ADServiceAccount -Identity gmsa-web to remove the account from that computer.
  3. Repeat on every other host that has it installed.
  4. Remove the computer from the gMSA's security group, or from PrincipalsAllowedToRetrieveManagedPassword.
  5. Delete the account from Active Directory with Remove-ADServiceAccount -Identity gmsa-web.

Deleting the object from the Managed Service Accounts container in Active Directory Users and Computers also works, but it skips the local clean-up that Uninstall-ADServiceAccount does on each host.

gMSA not working: Test-ADServiceAccount False and other errors

New-ADServiceAccount fails with a "key does not exist" error

There is no KDS root key yet, or it has not reached the effective time and replicated.

  1. Run Add-KdsRootKey -EffectiveImmediately if no key exists.
  2. Wait up to 10 hours for replication, then run New-ADServiceAccount again.
  3. Check the KdsSvc Operational log for event ID 4004.

Test-ADServiceAccount returns False

The host is not in PrincipalsAllowedToRetrieveManagedPassword, or it has not restarted since joining the group.

  1. Run Get-ADServiceAccount -Identity gmsa-web | Select-Object * and check the allowed principals.
  2. Add the computer or its group if it is missing.
  3. Restart the host and run Test-ADServiceAccount -Identity gmsa-web -Verbose again.

Install-ADServiceAccount fails

PrincipalsAllowedToRetrieveManagedPassword is not set, or the session is not elevated.

  1. Set the property with Set-ADServiceAccount -Identity gmsa-web -PrincipalsAllowedToRetrieveManagedPassword gMSA-WebHosts.
  2. Open PowerShell as administrator and run Install-ADServiceAccount again.

A scheduled task running as the gMSA does not start

The account lacks the Log on as a batch job right, or the task was registered without the Password logon type.

  1. Grant Log on as a batch job to the gMSA on the server.
  2. Re-register the task with New-ScheduledTaskPrincipal -UserId "CONTOSO\gmsa-task$" -LogonType Password.

Clients cannot authenticate to the service with Kerberos

The service's SPN is missing from the gMSA, or the hosts do not support the gMSA's encryption types.

  1. Register the SPN with Set-ADServiceAccount -Identity gmsa-web -ServicePrincipalNames @{Add="HTTP/web.contoso.com"}.
  2. Configure AES encryption for the account, since hosts that block RC4 fail when no supported type is set.
  3. Check DNS records and clock sync between clients, hosts and domain controllers.

Creating a gMSA fails even though the name is free in your domain

gMSA names must be unique across the forest, and another domain already uses it.

  1. Pick a different name and run New-ADServiceAccount again.
gMSA not working with Kerberos: msDS-SupportedEncryptionTypes in the Attribute Editor
The gMSA's Attribute Editor tab shows the Kerberos encryption types it accepts, here a value of 28 including RC4_HMAC_MD5. (Image: Microsoft Q&A)

Managed service accounts in Active Directory FAQ

What is the difference between an MSA and a gMSA?

A standalone MSA works on one computer only. A gMSA provides the same automatic password and SPN management but can be used by many servers at once, which makes it the choice for web farms, load-balanced services and anything that may move between hosts.

How often does a gMSA password change?

Every 30 days by default. You can choose another interval with -ManagedPasswordIntervalInDays only when you create the gMSA; the value is read-only afterwards, so a different interval needs a new account.

Why does a managed service account name end with a dollar sign?

The SAM account name of a managed service account ends in $, and New-ADServiceAccount appends it if you leave it out. Type the name with the $ when you set a service or task to run as the account, for example CONTOSO\gmsa-web$.

Where are managed service accounts stored in Active Directory?

In the domain's Managed Service Accounts container, unless you choose another OU with the -Path parameter of New-ADServiceAccount. You can see them there in Active Directory Users and Computers.

Can I reset the password of a gMSA?

No. Reset-ADServiceAccountPassword applies only to standalone MSAs and runs on the computer where the sMSA is installed. gMSA passwords are computed by domain controllers and rotate on their own schedule.

Do I need a KDS root key for a standalone MSA?

No. The KDS root key is only needed for group managed service accounts, because domain controllers use it to compute gMSA passwords. Standalone MSAs have their password maintained by the computer they are linked to.

What is a delegated managed service account in Windows Server 2025?

A dMSA is a new account type in Windows Server 2025 that can replace a traditional service account. Authentication is tied to specific machine identities, and once it replaces an old account, that account's password stops working. Create one with New-ADServiceAccount -CreateDelegatedServiceAccount.

Can a gMSA be used for outbound connections only?

Yes. New-ADServiceAccount -RestrictToOutboundAuthenticationOnly creates a gMSA that can authenticate to other services but cannot be the target of inbound connections, so it is created without the DNS host name that inbound authentication needs.

Philip Celasco

Philip is a Texas-based technology writer and IT administrator at Techdows.com with more than 10 years of experience creating practical content for everyday users and professionals. He specializes in web browsers, particularly Chromium-based platforms such as Google Chrome, Microsoft Edge, Brave, and Opera. Through his work as an IT administrator, Philip has hands-on experience managing devices, configuring browser policies, troubleshooting software and network issues, and helping people resolve problems that affect productivity and security. His articles are based on practical testing and real-world technical experience. He covers browser settings, extensions, performance problems, privacy controls, security features, and Windows troubleshooting. Outside work, Philip enjoys the quieter side of life in Texas and stepping away from the screen when he can. He has two kids, two cats and loves to play golf with his mother during the weekends.

Leave a Reply

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