Project briefing illustration for directory groups: a flat tactical intelligence sheet in the style of Star Fox Assault.
PROJECT JOURNEY / Automation

PowerShell Active Directory Group Comparison

I used PowerShell to compare DoD users’ Active Directory groups while supporting Air Force systems with SMS Data Products Group. I developed the workflow around explicit identities and directional differences, then used invented accounts to explain the read-only method publicly.

PowerShellActive DirectoryTestingAutomation

Start with a question narrower than “why is access different?”

I wanted a quicker way to inspect why two apparently similar accounts had different group memberships. My starting idea was a read-only PowerShell comparison: show what belongs only to the first account, only to the second, and to both. I was trying to make the difference easier to review, not automatically make the accounts identical.

I developed the script through drafts preserved in a February 22, 2023 thread. I moved from approximate account-name matching toward explicit username prompts and membership collection. The surviving thread records those design changes but contains no successful runtime transcript; the public walkthrough below uses invented identities to explain the comparison.

THE CHALLENGE

Narrow the contract before writing more PowerShell

PROJECT STEPS

How I separate identity from comparison

Project briefing illustration for directory groups: a flat tactical intelligence sheet in the style of Star Fox Assault.
STEP 01 OF 04
Resolve identities

For a future read-only comparison, I would select one clearly identified account on each side, using invented identities or deliberately chosen accounts in an authorized test directory. I would stop or ask for an explicit selection if a lookup matched several accounts, so I could establish whose memberships I was comparing. My early idea of matching approximate names has no verified runtime result.

Select a step to follow the project.
Read all step descriptions
  1. Resolve identities

    For a future read-only comparison, I would select one clearly identified account on each side, using invented identities or deliberately chosen accounts in an authorized test directory. I would stop or ask for an explicit selection if a lookup matched several accounts, so I could establish whose memberships I was comparing. My early idea of matching approximate names has no verified runtime result.

  2. Collect memberships

    I would collect the group identifiers listed directly on each account and keep account-lookup or collection failures separate from the results. This would prevent a missing account from appearing to be a valid account with no groups. I would limit the comparison to direct membership; inherited groups, primary-group behavior, and actual access to resources would need separate evidence.

  3. Compare sets

    In my explanatory comparison, I keep the list-comparison logic separate from the part that reads Active Directory, Microsoft’s account directory. I use invented, stable group identifiers, remove duplicates, and sort the results into groups belonging only to A, only to B, or to both accounts so they are easy to review. These examples illustrate the design, while successful execution of the historical PowerShell draft remains unverified.

  4. Review the report

    I would show the identified accounts, collection time, direct-membership scope, differences in each direction, and lookup errors in the report so reviewers could distinguish findings from missing data. The report would only describe memberships and make no access changes. To complete a recreation, I would still need a passing record of a synthetic example and a written guide for running it.

Prototype design: resolve each identity successfully before interpreting an empty or different membership set.

I settled on three clearly labeled outputs: direct group identifiers found only in account A, only in account B, and in both. That contract gives a reviewer something concrete to inspect. A difference can prompt an investigation, but it does not explain why the accounts differ or authorize an access change.

I also needed to define what the report leaves out. Direct membership, nested membership, and effective access answer different questions. Resource ACLs, application roles, and primary-group behavior can affect access beyond the direct group list. I therefore describe this as a direct-membership comparison.

The account lookup was the tricky part of the early design. A friendly-name search can return more than one person, and group display names can be duplicated or renamed. I moved the later draft toward explicit username prompts and made unique identity resolution a requirement for a recreation. Approximate matching stayed an unverified idea; I would require an explicit selection whenever a lookup returned multiple candidates.

Reconstruct the set comparison with invented data

For the explanatory version, I separated the directory adapter from the set comparison. The adapter would handle collection and lookup errors; the comparison would receive two successful collections and have no dependency on credentials, hostnames, or directory connectivity.

I used the following small PowerShell fixture to explain the algorithm. These invented identifiers form a new reconstruction, not the recovered historical script:

Illustrative powershell example
$groupsA = @('GROUP-READ', 'GROUP-EDIT')
$groupsB = @('GROUP-READ', 'GROUP-REVIEW')

$aOnly = @($groupsA | Where-Object { $_ -notin $groupsB } | Sort-Object -Unique)
$bOnly = @($groupsB | Where-Object { $_ -notin $groupsA } | Sort-Object -Unique)
$shared = @($groupsA | Where-Object { $_ -in $groupsB } | Sort-Object -Unique)

[pscustomobject]@{
    AccountAOnly = $aOnly
    AccountBOnly = $bOnly
    Shared = $shared
}

The expected A-only result is GROUP-EDIT, the B-only result is GROUP-REVIEW, and GROUP-READ is shared. I sort the output to make repeated reports easier to compare and remove duplicate identifiers so a repeated input does not create a misleading extra row.

I kept this example readable rather than optimizing it for a large directory. A larger implementation would use set structures with an explicit identifier-comparison rule. I would retain the original identifier as the key and attach a readable label for presentation.

Design the tests around misleading results

I turned the edge cases into the following fixture plan, with expected outputs to be written before execution:

  • Identical memberships produce no directional differences
  • Disjoint memberships put every group in one directional output
  • Two empty collections are a valid equal result
  • One empty collection leaves all groups on the other side
  • Repeated identifiers do not duplicate report rows
  • A missing account returns a lookup error, never an empty membership set
  • Duplicate display names require exact identity selection
  • A nested-group example is labeled outside the direct-membership scope

The missing-account case became the most important design check. If I converted a failed lookup into an empty array, the tool could falsely report that the account lacked every group. I keep collection status separate from membership data so missing evidence cannot masquerade as a valid empty result. This is a test plan for a recreation, not a claim that the original draft passed it.

Illustrative report rows using invented labels; these describe expected output, not a live directory run.

Collection stateReport result
A and B both collected successfullyA-only, B-only, and shared identifiers
A resolved; B lookup failedStop and report the B lookup error
Both accounts collected; both sets emptySuccessful empty comparison

Leave live collection behind a clear boundary

My next implementation step would be a read-only adapter in an authorized test directory, using the PowerShell ActiveDirectory module and two deliberately selected test identities. I would resolve both identities uniquely before collection and stop with a specific lookup error if either one failed.

The preserved drafts used MemberOf and related group lookups, which is why direct membership remains the scope of this article. I have not demonstrated the correctness of the proposed approximate-matching feature.

I keep group-addition and group-removal commands out of this diagnostic design. If a later workflow proposes an access change, I would treat it as a separate operation with its own review and authorization.

Make the result readable, then prove the implementation

I want the eventual report to show the membership scope, collection time, resolved identity labels, directional results, and lookup errors. The private report would retain stable identifiers; the public example uses invented labels. If I add CSV export, I will test quoting, stable ordering, and a file with no differences.

Using this comparison in systems administration taught me to make identity and membership scope explicit before adding convenience features. The preserved drafts show the design progressing, but do not supply a runtime transcript or measured time savings. A current recreation would still need a sanitized implementation, passing synthetic checks, and a runbook explaining direct membership versus effective access.

PROJECT WALKTHROUGH

Used in DoD systems administration; February 2023 drafts preserve the design progression. No runtime transcript or measured time savings was recovered; the public synthetic example is a later explanatory reconstruction.

Validation & limitations

  • Used in DoD systems administration; February 2023 drafts preserve the design progression. No runtime transcript or measured time savings was recovered; the public synthetic example is a later explanatory reconstruction.

Project records

  • Project artifacts and historical records, February 2023
  • Restoration and public documentation, October 1, 2026
END OF PROJECT FILE RETURN TO ARCHIVE