GuíasGuides · Nivel 2Level 2

Windows Server: servicios y tareas programadas con cuentas de servicio administradas (gMSA) y un servicio que no arranca tras un cambio de contraseñaWindows Server: services and scheduled tasks with group Managed Service Accounts (gMSA), and a service that won't start after a password change

Qué cuenta usar para un servicio, la clave raíz KDS, New-ADServiceAccount con el grupo de servidores autorizados, Install-ADServiceAccount y Test-ADServiceAccount, la gMSA en un servicio y en una tarea programada, y el ticket del servicio que no arranca por un error de inicio de sesión (eventos 7000 y 7038).Which account to use for a service, the KDS root key, New-ADServiceAccount with the group of allowed servers, Install-ADServiceAccount and Test-ADServiceAccount, the gMSA on a service and on a scheduled task, and the ticket about a service that won't start because of a logon failure (events 7000 and 7038).

Qué vas a conseguir

Sacar los servicios y las tareas programadas de las cuentas svc- con una contraseña que alguien apuntó en una hoja hace años, y pasarlos a cuentas de servicio administradas de grupo (gMSA): Active Directory genera y cambia la contraseña solo, y solo los servidores autorizados pueden usarla. Y, mientras quede alguna cuenta antigua, resolver en diez minutos el ticket del servicio que no arranca porque alguien le cambió la contraseña.

Antes de empezar

  • Un dominio con controladores de dominio Windows Server 2012 o posterior (cualquier versión con soporte lo cumple).
  • Permisos para crear objetos en OU=Cuentas de servicio,DC=contoso,DC=local y, una vez por bosque, alguien de Administradores de empresa o Administradores del dominio para la clave KDS.
  • En cada servidor que use la gMSA, el módulo de AD: Install-WindowsFeature RSAT-AD-PowerShell.
  • El inventario de lo que corre con cuentas de dominio. Empieza por aquí:
PowerShell (administrador) · srv-app02
Get-CimInstance Win32_Service | Where-Object StartName -like 'CONTOSO\*' | Select-Object Name, StartName, State, StartModeName             StartName              State   StartMode----             ---------              -----   ---------ContosoFacturas  CONTOSO\svc-facturas   Running AutoGet-ScheduledTask | Where-Object { $_.Principal.UserId -like '*svc-*' } | Select-Object TaskPath, TaskName, @{n='Cuenta';e={$_.Principal.UserId}}TaskPath   TaskName             Cuenta--------   --------             ------\Contoso\  Exportar facturas    CONTOSO\svc-facturas

1. Qué cuenta usar

CuentaDónde valeContraseñaCuándo
Cuenta virtual (NT SERVICE\Servicio)Solo en ese servidor; en la red, como la cuenta del equipoNingunaEl servicio no necesita entrar en otros servidores
Cuenta de usuario del dominio (svc-)Cualquier servidorLa pones y la cambias túSolo si la aplicación no admite otra cosa
gMSA (gmsa-informes$)Los servidores del grupo autorizadoAD la genera (240 caracteres) y la cambia cada 30 díasUn servicio, una tarea o un grupo de IIS que entra en SQL Server, un recurso compartido o AD

Una gMSA por aplicación, no una para todo: si alguien la usa mal, el alcance es una aplicación.

2. La clave raíz KDS (una vez por bosque)

Los controladores de dominio calculan las contraseñas de las gMSA a partir de una clave raíz KDS. Comprueba si ya existe:

PowerShell · controlador de dominio (Administradores de empresa)
Get-KdsRootKeyAdd-KdsRootKey -EffectiveImmediatelyGuid----4e1b5c3a-8d2f-4b6e-9a71-0c3d5e7f9b12
  • Con -EffectiveImmediately, la clave no se puede usar hasta 10 horas después: es el margen para que replique a todos los controladores. Créala la víspera.
  • En un laboratorio con un solo controlador se salta la espera con Add-KdsRootKey -EffectiveTime ((Get-Date).AddHours(-10)). En producción, no.

3. Crear la gMSA

Primero un grupo con los servidores que podrán usarla; después la cuenta:

PowerShell · RSAT, módulo ActiveDirectory
New-ADGroup -Name 'GG-gMSA-Informes' -GroupScope Global -Path 'OU=Cuentas de servicio,DC=contoso,DC=local'Add-ADGroupMember -Identity 'GG-gMSA-Informes' -Members 'SRV-GESTION01$'New-ADServiceAccount -Name 'gmsa-informes' -DNSHostName 'gmsa-informes.contoso.local' -PrincipalsAllowedToRetrieveManagedPassword 'GG-gMSA-Informes' -Path 'OU=Cuentas de servicio,DC=contoso,DC=local'Get-ADServiceAccount gmsa-informes -Properties PrincipalsAllowedToRetrieveManagedPassword, ManagedPasswordIntervalInDays | Select-Object Name, ManagedPasswordIntervalInDays, PrincipalsAllowedToRetrieveManagedPasswordName          ManagedPasswordIntervalInDays PrincipalsAllowedToRetrieveManagedPassword----          ----------------------------- ------------------------------------------gmsa-informes                            30 {CN=GG-gMSA-Informes,OU=Cuentas de servicio,DC=contoso,DC=local}
  • El nombre tiene un máximo de 15 caracteres: es el sAMAccountName, al que AD añade el $.
  • Un servidor que acabas de añadir al grupo no lo sabe hasta que renueva su ticket de Kerberos: reinícialo o, sin reiniciar, klist -li 0x3e7 purge en ese servidor.

4. Instalar y probar en el servidor

PowerShell (administrador) · srv-gestion01
Install-ADServiceAccount gmsa-informesTest-ADServiceAccount gmsa-informesTrue

True significa que este servidor puede pedir la contraseña a AD. False casi siempre es uno de tres: el servidor no está en el grupo, no ha renovado su ticket desde que lo añadiste o la clave KDS todavía no es efectiva.

5. Asignarla a un servicio

En services.msc, el servicio › Propiedades › Iniciar sesión:

Propiedades de ContosoInformes · Iniciar sesión
Esta cuenta: CONTOSO\gmsa-informes$
Contraseña(vacía)
Confirmar contraseña(vacía)
Aplicar
Se ha concedido a la cuenta CONTOSO\gmsa-informes$ el derecho Iniciar sesión como servicio.

Desde la línea de comandos, en una consola cmd (en Windows PowerShell 5.1 las comillas vacías no llegan a sc.exe):

Símbolo del sistema (administrador) · srv-gestion01
sc.exe config ContosoInformes obj= "CONTOSO\gmsa-informes$" password= ""[SC] ChangeServiceConfig CORRECTOsc.exe stop ContosoInformes && sc.exe start ContosoInformes
  • sc.exe no concede el derecho Iniciar sesión como servicio: si lo usas, dalo por GPO en Asignación de derechos de usuario o el servicio no arrancará (evento 7041).
  • Después, los permisos que la aplicación necesita, a la gMSA y nada más: su base de datos en SQL Server (CREATE LOGIN [CONTOSO\gmsa-informes$] FROM WINDOWS), su carpeta compartida, su OU.

6. Asignarla a una tarea programada

La interfaz del Programador de tareas pide una contraseña y no sirve para una gMSA. Con PowerShell:

PowerShell (administrador) · srv-gestion01
$quien = New-ScheduledTaskPrincipal -UserId 'CONTOSO\gmsa-informes$' -LogonType PasswordSet-ScheduledTask -TaskName 'Exportar informes' -TaskPath '\Contoso\' -Principal $quien(Get-ScheduledTask -TaskName 'Exportar informes' -TaskPath '\Contoso\').Principal | Select-Object UserId, LogonTypeUserId          LogonType------          ---------gmsa-informes$  Password

La gMSA necesita el derecho Iniciar sesión como proceso por lotes en el servidor. Un ejemplo completo de tarea con gMSA, con el script y sus comprobaciones, está en el informe semanal de Active Directory con PowerShell.

7. El ticket: "el servicio no arranca después del cambio de contraseña"

Lunes, 7:50. La aplicación de facturación no responde. En srv-app02, el servicio ContosoFacturas está detenido y al arrancarlo: Error 1069: El servicio no se inició debido a un error de inicio de sesión.

PowerShell (administrador) · srv-app02
Get-WinEvent -FilterHashtable @{LogName='System'; ProviderName='Service Control Manager'; Id=7000,7038,7041; StartTime=(Get-Date).AddDays(-3)} | Select-Object TimeCreated, Id, Message -First 2 | Format-ListTimeCreated : 03/11/2026 7:52:10Id          : 7038Message     : El servicio ContosoFacturas no pudo iniciar sesión como CONTOSO\svc-facturas con la contraseña configurada actualmente debido al siguiente error: El nombre de usuario o la contraseña no son correctos.TimeCreated : 03/11/2026 7:52:10Id          : 7000Message     : El servicio ContosoFacturas no pudo iniciarse debido al siguiente error: El servicio no se ha iniciado debido a un error de inicio de sesión.
  • 7038 + 7000: la contraseña guardada en el servicio ya no es la de AD.
  • 7041: la contraseña es buena, pero a la cuenta le falta el derecho Iniciar sesión como servicio (una GPO de seguridad lo ha sobrescrito).

Después, la cuenta en AD:

PowerShell · RSAT
Get-ADUser svc-facturas -Properties PasswordLastSet, LockedOut, Enabled, AccountExpirationDate | Select-Object Enabled, LockedOut, PasswordLastSet, AccountExpirationDateEnabled LockedOut PasswordLastSet      AccountExpirationDate------- --------- ---------------      ---------------------   True      True 31/10/2026 18:04:33

La contraseña se cambió el viernes (PasswordLastSet) y la cuenta está bloqueada: el servicio, y probablemente otros servidores con la misma cuenta, siguen probando la contraseña vieja. Por eso el inventario del principio importa: hay que cambiarla en todos los sitios donde se usa, o la cuenta se vuelve a bloquear en minutos.

  1. La contraseña nueva, del gestor de contraseñas del equipo (o la pide el responsable de la aplicación).
  2. En cada servidor y en cada tarea que usa svc-facturas: Propiedades › Iniciar sesión con la contraseña nueva (o sc.exe config ContosoFacturas obj= "CONTOSO\svc-facturas" password= "..." desde cmd).
  3. Unlock-ADAccount svc-facturas y Start-Service ContosoFacturas. Comprueba que la aplicación responde y que no hay nuevos 7038.
  4. El arreglo de verdad, en un cambio planificado: una gMSA gmsa-facturas con los puntos 3 a 6, permisos en SQL Server y la cuenta svc-facturas deshabilitada tras dos semanas sin uso.

Si el servicio ya corría con una gMSA y da 7000, la causa es otra: Test-ADServiceAccount en ese servidor. Casi siempre es un servidor nuevo o reinstalado que nadie añadió al grupo GG-gMSA-....

En el ticket: servicio, eventos, estado de la cuenta, dónde se cambió la contraseña y la propuesta de pasar a gMSA.

Siguientes pasos

  • La guía de IIS tiene el mismo problema en un grupo de aplicaciones (el evento 5021 de WAS) y la misma solución.
  • La primera guía de Windows Server explica cómo leer el visor de eventos con filtros como los de aquí.
  • Las cuentas de servicio que no pueden ser gMSA son candidatas a un gestor de acceso privilegiado con rotación automática, como el de la guía de CyberArk del Nivel 4.

¿Falta algo o en tu entorno es distinto? Escríbeme y lo corrijo.

What you'll get

Moving services and scheduled tasks off svc- accounts whose password somebody wrote in a spreadsheet years ago, and onto group Managed Service Accounts (gMSA): Active Directory generates and changes the password by itself, and only authorised servers can use it. And, while any old account is left, solving in ten minutes the ticket about a service that won't start because someone changed its password.

Before you start

  • A domain with Windows Server 2012 or later domain controllers (any supported version meets this).
  • Permissions to create objects in OU=Service Accounts,DC=contoso,DC=local and, once per forest, someone in Enterprise Admins or Domain Admins for the KDS key.
  • On every server that uses the gMSA, the AD module: Install-WindowsFeature RSAT-AD-PowerShell.
  • An inventory of what runs under domain accounts. Start here:
PowerShell (administrator) · srv-app02
Get-CimInstance Win32_Service | Where-Object StartName -like 'CONTOSO\*' | Select-Object Name, StartName, State, StartModeName             StartName              State   StartMode----             ---------              -----   ---------ContosoInvoices  CONTOSO\svc-invoices   Running AutoGet-ScheduledTask | Where-Object { $_.Principal.UserId -like '*svc-*' } | Select-Object TaskPath, TaskName, @{n='Account';e={$_.Principal.UserId}}TaskPath   TaskName             Account--------   --------             -------\Contoso\  Export invoices      CONTOSO\svc-invoices

1. Which account to use

AccountWhere it worksPasswordWhen
Virtual account (NT SERVICE\Service)Only on that server; on the network, as the computer accountNoneThe service does not need to reach other servers
Domain user account (svc-)Any serverYou set it and change itOnly if the application supports nothing else
gMSA (gmsa-reports$)The servers in the allowed groupAD generates it (240 characters) and changes it every 30 daysA service, task or IIS pool that reaches SQL Server, a share or AD

One gMSA per application, not one for everything: if it is misused, the blast radius is one application.

2. The KDS root key (once per forest)

Domain controllers derive gMSA passwords from a KDS root key. Check whether one already exists:

PowerShell · domain controller (Enterprise Admins)
Get-KdsRootKeyAdd-KdsRootKey -EffectiveImmediatelyGuid----4e1b5c3a-8d2f-4b6e-9a71-0c3d5e7f9b12
  • With -EffectiveImmediately, the key can not be used until 10 hours later: that is the margin for it to replicate to every DC. Create it the day before.
  • In a lab with a single DC you can skip the wait with Add-KdsRootKey -EffectiveTime ((Get-Date).AddHours(-10)). Not in production.

3. Create the gMSA

First a group with the servers that will be able to use it; then the account:

PowerShell · RSAT, ActiveDirectory module
New-ADGroup -Name 'GG-gMSA-Reports' -GroupScope Global -Path 'OU=Service Accounts,DC=contoso,DC=local'Add-ADGroupMember -Identity 'GG-gMSA-Reports' -Members 'SRV-MGMT01$'New-ADServiceAccount -Name 'gmsa-reports' -DNSHostName 'gmsa-reports.contoso.local' -PrincipalsAllowedToRetrieveManagedPassword 'GG-gMSA-Reports' -Path 'OU=Service Accounts,DC=contoso,DC=local'Get-ADServiceAccount gmsa-reports -Properties PrincipalsAllowedToRetrieveManagedPassword, ManagedPasswordIntervalInDays | Select-Object Name, ManagedPasswordIntervalInDays, PrincipalsAllowedToRetrieveManagedPasswordName         ManagedPasswordIntervalInDays PrincipalsAllowedToRetrieveManagedPassword----         ----------------------------- ------------------------------------------gmsa-reports                            30 {CN=GG-gMSA-Reports,OU=Service Accounts,DC=contoso,DC=local}
  • The name has a maximum of 15 characters: it is the sAMAccountName, to which AD adds the $.
  • A server you have just added to the group does not know until it renews its Kerberos ticket: restart it or, without restarting, run klist -li 0x3e7 purge on that server.

4. Install and test on the server

PowerShell (administrator) · srv-mgmt01
Install-ADServiceAccount gmsa-reportsTest-ADServiceAccount gmsa-reportsTrue

True means this server can ask AD for the password. False is almost always one of three: the server is not in the group, it has not renewed its ticket since you added it, or the KDS key is not effective yet.

5. Assign it to a service

In services.msc, the service › Properties › Log On:

ContosoReports Properties · Log On
This account: CONTOSO\gmsa-reports$
Password(blank)
Confirm password(blank)
Apply
The account CONTOSO\gmsa-reports$ has been granted the Log On As A Service right.

From the command line, in a cmd console (in Windows PowerShell 5.1 empty quotes do not reach sc.exe):

Command Prompt (administrator) · srv-mgmt01
sc.exe config ContosoReports obj= "CONTOSO\gmsa-reports$" password= ""[SC] ChangeServiceConfig SUCCESSsc.exe stop ContosoReports && sc.exe start ContosoReports
  • sc.exe does not grant the Log on as a service right: if you use it, grant it through GPO under User Rights Assignment or the service will not start (event 7041).
  • Then the permissions the application needs, to the gMSA and nothing more: its SQL Server database (CREATE LOGIN [CONTOSO\gmsa-reports$] FROM WINDOWS), its share, its OU.

6. Assign it to a scheduled task

The Task Scheduler interface asks for a password and does not work for a gMSA. With PowerShell:

PowerShell (administrator) · srv-mgmt01
$runas = New-ScheduledTaskPrincipal -UserId 'CONTOSO\gmsa-reports$' -LogonType PasswordSet-ScheduledTask -TaskName 'Export reports' -TaskPath '\Contoso\' -Principal $runas(Get-ScheduledTask -TaskName 'Export reports' -TaskPath '\Contoso\').Principal | Select-Object UserId, LogonTypeUserId         LogonType------         ---------gmsa-reports$  Password

The gMSA needs the Log on as a batch job right on the server. A complete example of a task with a gMSA, with the script and its checks, is in the weekly Active Directory report with PowerShell.

7. The ticket: "the service won't start after the password change"

Monday, 7:50. The invoicing app is not responding. On srv-app02, the ContosoInvoices service is stopped and starting it gives: Error 1069: The service did not start due to a logon failure.

PowerShell (administrator) · srv-app02
Get-WinEvent -FilterHashtable @{LogName='System'; ProviderName='Service Control Manager'; Id=7000,7038,7041; StartTime=(Get-Date).AddDays(-3)} | Select-Object TimeCreated, Id, Message -First 2 | Format-ListTimeCreated : 03/11/2026 7:52:10Id          : 7038Message     : The ContosoInvoices service was unable to log on as CONTOSO\svc-invoices with the currently configured password due to the following error: The user name or password is incorrect.TimeCreated : 03/11/2026 7:52:10Id          : 7000Message     : The ContosoInvoices service failed to start due to the following error: The service did not start due to a logon failure.
  • 7038 + 7000: the password stored in the service is no longer the one in AD.
  • 7041: the password is fine, but the account is missing the Log on as a service right (a security GPO has overwritten it).

Then the account in AD:

PowerShell · RSAT
Get-ADUser svc-invoices -Properties PasswordLastSet, LockedOut, Enabled, AccountExpirationDate | Select-Object Enabled, LockedOut, PasswordLastSet, AccountExpirationDateEnabled LockedOut PasswordLastSet      AccountExpirationDate------- --------- ---------------      ---------------------   True      True 31/10/2026 18:04:33

The password was changed on Friday (PasswordLastSet) and the account is locked out: the service, and probably other servers using the same account, keep trying the old password. That is why the inventory at the start matters: it has to be changed in every place it is used, or the account locks again within minutes.

  1. The new password, from the team's password manager (or from the application owner).
  2. On every server and every task that uses svc-invoices: Properties › Log On with the new password (or sc.exe config ContosoInvoices obj= "CONTOSO\svc-invoices" password= "..." from cmd).
  3. Unlock-ADAccount svc-invoices and Start-Service ContosoInvoices. Check that the app responds and that there are no new 7038 events.
  4. The real fix, in a planned change: a gmsa-invoices gMSA following steps 3 to 6, permissions in SQL Server, and the svc-invoices account disabled after two weeks unused.

If the service already ran under a gMSA and gives 7000, the cause is different: Test-ADServiceAccount on that server. It is nearly always a new or rebuilt server that nobody added to the GG-gMSA-... group.

In the ticket: service, events, account state, where the password was changed and the proposal to move to a gMSA.

Next steps

  • The IIS guide has the same problem on an application pool (WAS event 5021) and the same solution.
  • The first Windows Server guide explains how to read Event Viewer with filters like the ones here.
  • Service accounts that cannot become gMSAs are candidates for a privileged access manager with automatic rotation, like the one in the Level 4 CyberArk guide.

Is something missing, or different in your environment? Get in touch and I'll fix it.

Tech Career Lab · newsletter

¿Te ha servido? Cada dos semanas envío una idea práctica para perfiles IT: LinkedIn, proyectos, networking y procesos de selección.Found this useful? Every two weeks I send one practical idea for IT professionals: LinkedIn, projects, networking and hiring processes.

Apúntate y llévate las 33 ideasSign up and get the 33 ideas →