Skip to content

Add computer name targeting to AD domain state - #2002

Open
soulemike wants to merge 3 commits into
maester365:mainfrom
soulemike:codex/create-branch-for-issue-1974
Open

Add computer name targeting to AD domain state#2002
soulemike wants to merge 3 commits into
maester365:mainfrom
soulemike:codex/create-branch-for-issue-1974

Conversation

@soulemike

@soulemike soulemike commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

📑 Description

Adds an optional param for the target of the caching commands with a default of the current domain. May need future mapping in other commands.

Allow callers to target a specific domain controller or DNS server when collecting AD domain state so sub-commands that require a host can be directed explicitly.
Preserve existing behavior by falling back to the collected domain object's DNS root when no computer name is supplied.
Ensure cached domain state is separated per target host to avoid overwriting or reusing results collected for a different server.
Description
Added an optional ComputerName parameter and updated the command help with examples describing its use.
Build @adServerParameters when -ComputerName is provided and splat it to supported Get-AD* calls so those queries target the specified AD Server.
Introduced resolvedComputerName = if ($ComputerName) { $ComputerName } else { $domainState.Domain.DNSRoot } and use it for DNS and LDAP sub-commands, including Get-DnsServerZone, Get-DnsServerResourceRecord, and the LDAP:// search root for DirectorySearcher.
Use a cache key that includes the ComputerName (DomainState:$ComputerName) when a target host is specified so targeted collections do not clash with the default cache.

Closes #1974

✅ Checks

  • My pull request adheres to the code style of this project.
  • My code requires changes to the documentation.
  • I have updated the documentation as required.
  • The build and unit tests pass after running /powershell/tests/pester.ps1 locally.

ℹ️ Additional Information

Summary by CodeRabbit

  • New Features
    • Added an optional -ComputerName parameter to Get-MtADDomainState to collect domain and DNS state from a specified DNS server/domain controller.
    • Updated help text and examples to document the new parameter.
  • Bug Fixes
    • DNS zone and DNS record collection now targets the specified (or defaulted) ComputerName instead of using the local DNS context.

@soulemike
soulemike requested a review from a team as a code owner July 25, 2026 21:30
@coderabbitai

coderabbitai Bot commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Get-MtADDomainState now accepts an optional -ComputerName for DNS collection, defaults it to the domain’s DNSRoot when omitted, and passes it to DNS zone and resource-record queries.

Changes

Targeted DNS collection

Layer / File(s) Summary
DNS target selection and collection
powershell/public/Get-MtADDomainState.ps1
Documents and adds the optional -ComputerName parameter, defaults it to the collected domain’s DNSRoot, and uses it for DNS zone and resource-record queries.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The DNS targeting part of #1974 is addressed, but the requested configuration object for Get-MtADDomainState is not shown as implemented. Add the missing configuration data to Get-MtADDomainState and verify the DNS/config outputs satisfy #1974.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: adding computer-name targeting to AD domain state collection.
Description check ✅ Passed The description includes the required summary, linked issue reference, checklist, and additional information sections.
Out of Scope Changes check ✅ Passed The changes stay focused on AD domain-state targeting, help text, and DNS collection, with no clear unrelated additions.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@powershell/public/Get-MtADDomainState.ps1`:
- Line 75: Update the resolved computer name and DACL binding logic around
$resolvedComputerName so omitting -ComputerName preserves the serverless
LDAP://$domainDN path. Only construct an explicit LDAP://$ComputerName/$domainDN
DirectoryEntry with AuthenticationTypes.ServerBind when -ComputerName is
supplied, and apply the same adjustment to the corresponding logic around the
referenced additional locations.
- Around line 15-17: Update the ComputerName documentation in
Get-MtADDomainState to state that it must identify an Active Directory domain
controller or AD DS server, not a DNS-only server. Clarify that DNS collection
uses the same target only when it also supports the required DNS management
access, or introduce separate AD and DNS target parameters if the implementation
supports that scope.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 05d0ce35-7a80-481b-98fc-22a15458718a

📥 Commits

Reviewing files that changed from the base of the PR and between 50595be and 298cc0f.

📒 Files selected for processing (1)
  • powershell/public/Get-MtADDomainState.ps1

Comment thread powershell/public/Get-MtADDomainState.ps1 Outdated
Comment thread powershell/public/Get-MtADDomainState.ps1 Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@powershell/public/Get-MtADDomainState.ps1`:
- Around line 70-72: Update Get-MtADDomainState to resolve the explicit
ComputerName before AD data collection and pass it to all supported AD cmdlets,
not only the Get-DnsServer* calls; ensure the LDAP searcher also targets
ComputerName when provided while retaining serverless behavior when it is
absent. Apply the related changes at powershell/public/Get-MtADDomainState.ps1
lines 56-66, 70-72, and 211, using the existing domainState collection flow and
ComputerName handling.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 7b6957cb-d5ee-40dc-83d8-959fdb15ea47

📥 Commits

Reviewing files that changed from the base of the PR and between 298cc0f and d4d3e5c.

📒 Files selected for processing (1)
  • powershell/public/Get-MtADDomainState.ps1

Comment on lines +70 to +72
if (-not $ComputerName) {
$ComputerName = $domainState.Domain.DNSRoot
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== locate file =="
git ls-files | rg 'Get-MtADDomainState\.ps1$' || true

echo "== relevant file around lines 1-130 =="
if [ -f powershell/public/Get-MtADDomainState.ps1 ]; then
  sed -n '1,130p' powershell/public/Get-MtADDomainState.ps1 | cat -n
fi

echo "== relevant file around lines 180-230 =="
if [ -f powershell/public/Get-MtADDomainState.ps1 ]; then
  sed -n '180,230p' powershell/public/Get-MtADDomainState.ps1 | cat -n
fi

echo "== full file metadata =="
wc -l powershell/public/Get-MtADDomainState.ps1

echo "== ComputerName usages =="
rg -n '\bComputerName\b|\b-\s*Server\b|Get-AD|LDAP://' powershell/public/Get-MtADDomainState.ps1

Repository: maester365/maester

Length of output: 14440


🏁 Script executed:

#!/bin/bash
set -euo pipefail

python3 - <<'PY'
from pathlib import Path
p=Path('powershell/public/Get-MtADDomainState.ps1')
text=p.read_text()
print('has ComputerName param:', 'param' in text and '$ComputerName' in text)
print('computer name parameter block vicinity:', '$ComputerName' in text)
for line in enumerate(text.splitlines(), 1):
    if 'ComputerName' in line[1] or 'Get-AD' in line[1] or 'SearchRoot' in line[1]:
        print(f'{line[0]}: {line[1]}')
PY

# Read-only behavioral/static verifier: identify every Get-AD* and LDAP SearchRoot call
# and whether a local ComputerName variable is interpolated into its common target-oriented parameter.
import re, subprocess
from pathlib import Path

text = Path('powershell/public/Get-MtADDomainState.ps1').read_text()
lines = text.splitlines()

get_ad_calls = []
ldap_calls = []
for i,l in enumerate(lines,1):
    if re.search(r'Get-AD\w+', l):
        get_ad_calls.append((i,l.strip()))
    if 'SearchRoot = [ADSI]' in l or 'LDAP://' in l:
        ldap_calls.append((i,l.strip()))

print('== Get-AD calls ==')
for i,l in get_ad_calls: print(f'{i}: {l}')
print('== LDAP SearchRoot calls ==')
for i,l in ldap_calls: print(f'{i}: {l}')

print('== static probe: ComputerName passed to cmdlet/common target-like parameter near Get-AD calls? ==')
# Windows PowerShell Get-AD* cmdlets accept -Server as common parameter or per-cmdlet Server;
# check if any sampled call line contains "-ComputerName" or "ComputerName".
for class_ in ['Domain','Forest','Computer','User','Group','ServiceAccount','DomainController','ReplicationSite','ReplicationSubnet','RootDSE','OptionalFeature']:
    found=[x for x in get_ad_calls if 'Get-AD'+class_ in x[1]]
    passed=[x for x in found if re.search(r'(?i)\b(Server|Computer|Target)\b', x[1])]
    print('Get-AD'+class_+' count='+str(len(found))+' explicit target-like params='+str(len(passed)))
print('static probe done.')
PY

Repository: maester365/maester

Length of output: 3789


Propagate ComputerName consistently beyond DNS.

ComputerName is currently only passed to Get-DnsServer*; resolve and apply the explicit target to the supported AD cmdlets before collection, and honor it for the LDAP searcher while preserving the implicit serverless behavior when a target is not provided.

📍 Affects 1 file
  • powershell/public/Get-MtADDomainState.ps1#L70-L72 (this comment)
  • powershell/public/Get-MtADDomainState.ps1#L56-L66
  • powershell/public/Get-MtADDomainState.ps1#L211-L211
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@powershell/public/Get-MtADDomainState.ps1` around lines 70 - 72, Update
Get-MtADDomainState to resolve the explicit ComputerName before AD data
collection and pass it to all supported AD cmdlets, not only the Get-DnsServer*
calls; ensure the LDAP searcher also targets ComputerName when provided while
retaining serverless behavior when it is absent. Apply the related changes at
powershell/public/Get-MtADDomainState.ps1 lines 56-66, 70-72, and 211, using the
existing domainState collection flow and ComputerName handling.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@soulemike thoughts on this review coment?

@SamErde SamErde added enhancement New feature or request maester-test Related to a Maester test labels Jul 28, 2026

@SamErde SamErde left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request maester-test Related to a Maester test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🪲 AD tests. Missing DNS and Config informations

3 participants