# Groups in container objects count should be retrievable

This test identifies groups that are stored in container objects (distinguished names starting with 'CN=') rather than Organizational Units (OU=).

Source: https://maester.dev/docs/tests/AD-GRP-02

<!-- This file is generated by website/scripts/generate-test-docs.mjs. Do not edit manually. -->

<div class="test-byline"><div class="test-byline-avatars"><a class="test-byline-avatar test-byline-avatar--author" href="/contributors/soulemike" title="Michael Soule · Original author"><img src="https://github.com/soulemike.png" alt="Michael Soule" width="28" height="28" loading="lazy" decoding="async" /></a></div><div class="test-byline-meta"><span class="test-byline-text">Contributed by <a href="/contributors/soulemike">Michael Soule</a></span><a class="test-byline-link" href="/contributors">All contributors →</a></div></div>

<p class="test-part">Part of <a href="/docs/tests/ad">Active Directory</a> · Active Directory · Groups · <a href="/docs/tests">All checks</a></p>

```powershell title="Run this check"
Invoke-Maester -TestId AD-GRP-02
```

## Overview

- Active Directory supports two primary types of directory objects for storing other objects: Organizational Units (OUs) and Containers (CNs). While both can hold groups, they serve different purposes:
- **OUs (OU=)**: Designed for delegation, Group Policy application, and logical organization
- **Containers (CN=)**: System containers with limited flexibility (like CN=Users, CN=Computers)

- Storing groups in containers instead of OUs creates several issues:

- **Delegation limitations**: Cannot easily delegate management of container contents
- **No Group Policy**: Cannot link Group Policy Objects to containers
- **Poor organization**: Containers lack the hierarchical flexibility of OUs
- **Security risks**: Default containers like CN=Users are well-known targets

#### Control Type

**Operational**

#### Security Recommendation

- Move all groups from default containers (CN=Users, CN=Builtin) to appropriate OUs
- Design an OU structure that reflects your administrative delegation model
- Implement a Group Policy strategy that works with your OU design
- Regularly audit for new groups created in containers

#### How the Test Works

- This test retrieves all group objects from Active Directory and analyzes their DistinguishedName property:
- Counts groups with DNs starting with "CN=" (in containers)
- Counts groups with DNs containing "OU=" (in Organizational Units)
- Calculates the percentage of groups in containers

#### Related Tests

- `Test-MtAdGroupWithManagerCount` - Helps identify groups ready for delegated management
- `Test-MtAdGroupStaleCount` - Identifies groups that may need cleanup after reorganization

## Details

<details>
<summary>Every attribute of this check</summary>

| Field | Value |
| --- | --- |
| Test ID | AD-GRP-02 |
| Severity | Info |
| Suite | Active Directory |
| Product | Active Directory |
| Feature | Groups |
| Area | Infrastructure hardening |
| Resource type | Group |
| MITRE ATT&CK | None |
| PowerShell test | [Test-MtAdGroupInContainerCount](https://github.com/maester365/maester/blob/main/tests/ad/group/Test.AD-GRP-02.ps1) |
| Services | ActiveDirectory |
| Permissions | ActiveDirectory:Ldap:group:ReadProperty |

</details>

## Source

- Test: [`tests/ad/group/Test.AD-GRP-02.ps1`](https://github.com/maester365/maester/blob/main/tests/ad/group/Test.AD-GRP-02.ps1)
- Documentation: [`tests/ad/group/Test.AD-GRP-02.md`](https://github.com/maester365/maester/blob/main/tests/ad/group/Test.AD-GRP-02.md)
