<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Marius Ene's blog]]></title><description><![CDATA[Marius Ene's blog]]></description><link>https://mariusene.hashnode.dev</link><image><url>https://cdn.hashnode.com/res/hashnode/image/upload/v1750271482014/6d171ec0-3d4d-4fb3-9883-901b85b33228.png</url><title>Marius Ene&apos;s blog</title><link>https://mariusene.hashnode.dev</link></image><generator>RSS for Node</generator><lastBuildDate>Fri, 11 Sep 2026 17:59:28 GMT</lastBuildDate><atom:link href="https://mariusene.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[A Guide to Configuring AD Group Managed Service Accounts (gMSA)]]></title><description><![CDATA[Overview

Requirements

Create the Key Distribution Services KDS Root Key


Creating a new gMSA

Configuring Kerberos delegation


Removing a gMSA

Configuring a Scheduled Task

References


Overview
The below process is run only once, before startin...]]></description><link>https://mariusene.hashnode.dev/a-guide-to-configuring-ad-group-managed-service-accounts-gmsa</link><guid isPermaLink="true">https://mariusene.hashnode.dev/a-guide-to-configuring-ad-group-managed-service-accounts-gmsa</guid><category><![CDATA[Active Directory]]></category><category><![CDATA[Windows]]></category><category><![CDATA[windows server]]></category><category><![CDATA[Kerberos]]></category><dc:creator><![CDATA[Marius Ionut Ene]]></dc:creator><pubDate>Wed, 18 Jun 2025 18:29:02 GMT</pubDate><content:encoded><![CDATA[<ul>
<li><p><a target="_blank" href="https://travix.atlassian.net/wiki/spaces/EPICS/pages/3996286986/EPICS-660+-+POC+Lab+-+Configuring+AD+Group+Managed+Service+Accounts+gMSA#Overview">Overview</a></p>
</li>
<li><p><a target="_blank" href="https://travix.atlassian.net/wiki/spaces/EPICS/pages/3996286986/EPICS-660+-+POC+Lab+-+Configuring+AD+Group+Managed+Service+Accounts+gMSA#Requirements">Requirements</a></p>
<ul>
<li><a target="_blank" href="https://travix.atlassian.net/wiki/spaces/EPICS/pages/3996286986/EPICS-660+-+POC+Lab+-+Configuring+AD+Group+Managed+Service+Accounts+gMSA#Create-the-Key-Distribution-Services-KDS-Root-Key">Create the Key Distribution Services KDS Root Key</a></li>
</ul>
</li>
<li><p><a target="_blank" href="https://travix.atlassian.net/wiki/spaces/EPICS/pages/3996286986/EPICS-660+-+POC+Lab+-+Configuring+AD+Group+Managed+Service+Accounts+gMSA#Creating-a-new-gMSA">Creating a new gMSA</a></p>
<ul>
<li><a target="_blank" href="https://travix.atlassian.net/wiki/spaces/EPICS/pages/3996286986/EPICS-660+-+POC+Lab+-+Configuring+AD+Group+Managed+Service+Accounts+gMSA#Configuring-Kerberos-delegation">Configuring Kerberos delegation</a></li>
</ul>
</li>
<li><p><a target="_blank" href="https://travix.atlassian.net/wiki/spaces/EPICS/pages/3996286986/EPICS-660+-+POC+Lab+-+Configuring+AD+Group+Managed+Service+Accounts+gMSA#Removing-a-gMSA">Removing a gMSA</a></p>
</li>
<li><p><a target="_blank" href="https://travix.atlassian.net/wiki/spaces/EPICS/pages/3996286986/EPICS-660+-+POC+Lab+-+Configuring+AD+Group+Managed+Service+Accounts+gMSA#Configuring-a-Scheduled-Task">Configuring a Scheduled Task</a></p>
</li>
<li><p><a target="_blank" href="https://travix.atlassian.net/wiki/spaces/EPICS/pages/3996286986/EPICS-660+-+POC+Lab+-+Configuring+AD+Group+Managed+Service+Accounts+gMSA#References">References</a></p>
</li>
</ul>
<h2 id="heading-overview">Overview</h2>
<p>The below process is run only once, before starting to use gMSAs.</p>
<p>A standalone Managed Service Account (sMSA) is a managed domain account that provides automatic password management, simplified service principal name (SPN) management and the ability to delegate the management to other administrators. This type of managed service account (MSA) was introduced in Windows Server 2008 R2 and Windows 7.</p>
<p>The group Managed Service Account (gMSA) provides the same functionality within the domain and also extends that functionality over multiple servers. When you connect to a service hosted on a server farm, such as a Network Load Balanced solution, the authentication protocols supporting mutual authentication require all instances of the services to use the same principal. When you use a gMSA as a service principal, the Windows operating system manages the password for the account instead of relying on the administrator to manage the password.</p>
<p>The Microsoft Key Distribution Service (<code>kdssvc.dll</code>) lets you securely obtain the latest key or a specific key with a key identifier for an Active Directory account. The Key Distribution Service shares a secret that's used to create keys for the account. These keys periodically change. For a gMSA, the domain controller computes the password on the key that the Key Distribution Services provides, along with other attributes of the gMSA. Member hosts can obtain the current and preceding password values by contacting a domain controller.</p>
<p><strong>Note</strong>: Failover clusters don't support gMSAs. However, services that run on top of the Cluster service can use a gMSA or a sMSA if they're a Windows service, an app pool, a scheduled task, or natively support gMSA or sMSA.</p>
<h2 id="heading-requirements">Requirements</h2>
<p>If you are faced with the following error in Windows PowerShell, it means that you need to Create the Key Distribution Services KDS Root Key.</p>
<p><code>New-ADServiceAccount : Key does not exist</code></p>
<p><strong>Domain Admins</strong> or <strong>Enterprise Admins</strong> group membership, or equivalent, is the minimum required to complete this procedure.</p>
<h3 id="heading-create-the-key-distribution-services-kds-root-key">Create the Key Distribution Services KDS Root Key</h3>
<p>Domain Controllers (DC) require a root key to begin generating gMSA passwords. The domain controllers will wait up to 10 hours from time of creation to allow all domain controllers to converge their AD replication before allowing the creation of a gMSA. Waiting up to 10 hours is a safety measure to prevent password generation from occurring before all DCs in the environment are capable of answering gMSA requests. Trying to use a gMSA too soon might fail when the gMSA host attempts to retrieve the password, as the key may not have been replicated to all domain controllers. gMSA password retrieval failures can also occur when using DCs with limited replication schedules or if there's a replication issue.</p>
<p><strong>Note</strong>: Deleting and recreating the root key may lead to issues where the old key continues to be used after deletion due to caching of the key. The Key Distribution Service (KDC) should be restarted on all domain controllers if the root key is recreated.</p>
<ol>
<li><p>On a Windows Server 2012 or later domain controller, run the Windows PowerShell from the Taskbar.</p>
</li>
<li><p>At the command prompt for the Windows PowerShell Active Directory module, type the following commands, and then press ENTER:</p>
<p> <strong>Add-KdsRootKey -EffectiveImmediately</strong></p>
</li>
</ol>
<p><strong>Note</strong>: The parameter -<strong>EffectiveImmediately</strong> will add a root key to the target DC which will be used by the KDS service immediately. However, other domain controllers will not be able to use the root key until replication is successful.</p>
<p>You should see a Guid as output. For example:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1750270268665/f678f638-6a18-42ca-ac4d-0a9dbd3614cd.png" alt /></p>
<p>KDS root keys are stored in Active Directory in container <code>CN=Master Root Keys,CN=Group Key Distribution Service,CN=Services,CN=Configuration,DC=&lt;forest name&gt;;</code></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1750270556483/0f6b5626-6db5-4880-9366-289df1096fdf.png" alt /></p>
<div data-node-type="callout">
<div data-node-type="callout-emoji">💡</div>
<div data-node-type="callout-text"><strong>INFO</strong>: They have an attribute <strong>msKds-DomainID </strong>that links to the computer account of the Domain Controller that created the object. When this domain controller is demoted and removed from the domain, the value will refer to the tombstone of the computer account. You can ignore the broken value as it is only used to help the administrator track the object when it's freshly created. You may also change the attribute value and point it to the computer object of another domain controller in your forest.</div>
</div>

<h2 id="heading-creating-a-new-gmsa">Creating a new gMSA</h2>
<p>Here is the command I am running for this experiment. You will need to update the values to reflect your environment.</p>
<pre><code class="lang-powershell"><span class="hljs-built_in">New-ADServiceAccount</span> WriteDescSVC <span class="hljs-literal">-DNSHostName</span> WriteDescSVC.example.com `
                                  <span class="hljs-literal">-PrincipalsAllowedToRetrieveManagedPassword</span> SCCM<span class="hljs-variable">$</span> `
                                  <span class="hljs-literal">-KerberosEncryptionType</span> AES128, AES256 `
                                  <span class="hljs-literal">-ServicePrincipalNames</span> http/SCCM.example.com/example.com, `
                                                         http/SCCM.example.com/example, `
                                                         http/SCCM/example.com, `
                                                         http/SCCM/example <span class="hljs-literal">-Verbose</span>
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1750270378969/eb5327bd-aa9c-42ee-a8b5-4a0db8dd91f1.png" alt /></p>
<p>Now you should have it under <strong>CN=Managed Service Accounts,DC=yourDomain,DC=com</strong>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1750270541080/1b2cf8e2-e5e7-454b-b8b4-eb51cca7ca36.png" alt class="image--center mx-auto" /></p>
<p><strong>Note</strong>: The password change interval (default is 30 days) can be changed using the <strong>-ManagedPasswordIntervalInDays</strong> -parameter. Changin this interval after creation is not supported, you will need to recreate the gMSA.</p>
<div data-node-type="callout">
<div data-node-type="callout-emoji">💡</div>
<div data-node-type="callout-text"><strong>NOTE</strong>: The password change interval (default is 30 days) can be changed using the <strong>-ManagedPasswordIntervalInDays </strong>-parameter. Changin this interval after creation is not supported, you will need to recreate the gMSA.</div>
</div>

<h3 id="heading-configuring-kerberos-delegation">Configuring Kerberos delegation</h3>
<p>To configure delegation for these special accounts, you need to set the correct attributes manually. There are two attributes that you need to modify for these accounts:</p>
<ul>
<li><p><strong>userAccountControl</strong> defines the type of delegation</p>
</li>
<li><p><strong>msDS-AllowedToDelegateTo</strong> defines where the SPNs for delegation will be added</p>
</li>
</ul>
<p>The more secure and convenient way is by using PowerShell commands to update those attributes. You don't need to calculate final userAccountControl values when using PowerShell. Here are the commands to enable different types of delegation:</p>
<ul>
<li><p><strong>Do not trust this computer for delegation</strong></p>
<p>  PowerShellCopy</p>
<p>  <code>Set-ADAccountControl -Identity TestgMSA$ -TrustedForDelegation $false -TrustedToAuthForDelegation $false Set-ADServiceAccount -Identity TestgMSA$ -Clear 'msDS-AllowedToDelegateTo'</code></p>
</li>
<li><p><strong>Unconstrained Delegation/Trust This Computer for Delegation to any service</strong></p>
<p>  PowerShellCopy</p>
<p>  <code>Set-ADAccountControl -Identity TestgMSA$ -TrustedForDelegation $true -TrustedToAuthForDelegation $false Set-ADServiceAccount -Identity TestgMSA$ -Clear 'msDS-AllowedToDelegateTo'</code></p>
</li>
<li><p><strong>Kerberos Constrained Delegation/Trust this computer for delegation to specified services only (Use Kerberos Only)</strong></p>
<p>  PowerShellCopy</p>
<p>  <code>Set-ADAccountControl -Identity TestgMSA$ -TrustedForDelegation $false -TrustedToAuthForDelegation $false</code></p>
<p>  Update the Backend Service SPNs in msDS-AllowedToDelegateTo attribute.</p>
</li>
<li><p><strong>Kerberos Constrained Delegation with Protocol Transition/Trust this computer for delegation to specified services only (Use Any Authentication Protocol)</strong></p>
<p>  PowerShellCopy</p>
<p>  <code>Set-ADAccountControl -Identity TestgMSA$ -TrustedForDelegation $false -TrustedToAuthForDelegation $true</code></p>
<p>  Update the Backend Service SPNs in msDS-AllowedToDelegateTo attribute.</p>
</li>
</ul>
<p>By default the userAccountControl will be as in the image and the msDS-AllowedToDelegateTo will be empty.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1750270704602/88581035-dd53-4f46-b840-837bc85e19aa.png" alt /></p>
<p>Remember to test before if the application you want to use the gMSA for supports this type of account.</p>
<h2 id="heading-removing-a-gmsa">Removing a gMSA</h2>
<p>You can remove it by simply right clicking and deleting the gMSA.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1750270736825/e35b7e30-d202-460d-bb6d-548c4700b566.png" alt class="image--center mx-auto" /></p>
<p>To remove the cache from the servers the running the following PowerShell command:</p>
<p><code>Uninstall-ADServiceAccount &lt;ADServiceAccount&gt;</code> </p>
<h2 id="heading-configuring-a-scheduled-task">Configuring a Scheduled Task</h2>
<p>We can use PowerShell for this. Below is an example that you can adapt to your own requirements:</p>
<pre><code class="lang-powershell"><span class="hljs-variable">$action</span> = <span class="hljs-built_in">New-ScheduledTaskAction</span> <span class="hljs-literal">-Execute</span> <span class="hljs-string">"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"</span> <span class="hljs-literal">-Argument</span> <span class="hljs-string">"-File 'D:\Utils\Powershell\Stale_Objects\Disable_move_comps.ps1'"</span>

<span class="hljs-variable">$action</span> = <span class="hljs-built_in">New-ScheduledTaskAction</span> <span class="hljs-literal">-Execute</span> <span class="hljs-string">"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"</span> <span class="hljs-literal">-Argument</span> <span class="hljs-string">"-File 'D:\Utils\Powershell\Stale_Objects\Save_comps_to_file.ps1'"</span>
<span class="hljs-variable">$trigger</span> = <span class="hljs-built_in">New-ScheduledTaskTrigger</span> <span class="hljs-literal">-At</span> <span class="hljs-string">'2:10am'</span> <span class="hljs-literal">-Weekly</span> <span class="hljs-literal">-DaysOfWeek</span> Saturday
<span class="hljs-variable">$principal</span> = <span class="hljs-built_in">New-ScheduledTaskPrincipal</span> <span class="hljs-literal">-UserID</span> <span class="hljs-string">"Travix\Disable&amp;MoveSVC<span class="hljs-variable">$</span>"</span> <span class="hljs-literal">-LogonType</span> Password <span class="hljs-literal">-RunLevel</span> Highest

<span class="hljs-comment"># Uncheck if you want to modify an existing task. Comment the Register-ScheduledTask command next.</span>
<span class="hljs-comment">#Set-ScheduledTask -TaskName "EPICS - Stale Computer Objects" –Action $action –Trigger $trigger –Principal $principal </span>

<span class="hljs-comment"># Comment if you don't want to create a new one but use instead an existing task.</span>
<span class="hljs-built_in">Register-ScheduledTask</span> <span class="hljs-literal">-TaskName</span> <span class="hljs-string">"EPICS - Stale Computer Objects List"</span> <span class="hljs-literal">-Description</span> <span class="hljs-string">'08-04-2024 Marius: Migrated from BEGCP1ADC01. https://travix.atlassian.net/browse/EPICS-687'</span> –Action <span class="hljs-variable">$action</span> –Trigger <span class="hljs-variable">$trigger</span> –Principal <span class="hljs-variable">$principal</span>
</code></pre>
<p>If you are using the GUI to configure the task, the first time you create it if you set the gMSA and don’t set a password it will let you create it. However, if you try to edit it, it might ask you to input the password and won’t let you bypass that anymore, therefore, make sure you create it right from the beginning.</p>
<h2 id="heading-references">References</h2>
<p><a target="_blank" href="https://learn.microsoft.com/en-us/windows-server/security/group-managed-service-accounts/group-managed-service-accounts-overview">Group Managed Service Accounts Overview</a></p>
<p><a target="_blank" href="https://learn.microsoft.com/en-us/windows-server/security/group-managed-service-accounts/getting-started-with-group-managed-service-accounts">Get started with Group Managed Service Accounts</a></p>
<p><a target="_blank" href="https://learn.microsoft.com/en-us/windows-server/security/group-managed-service-accounts/create-the-key-distribution-services-kds-root-key">Create the Key Distribution Services KDS Root Key</a></p>
]]></content:encoded></item></channel></rss>