Computer: Add DeleteExistingComputerAccount parameter to DSC_Computer#462
Computer: Add DeleteExistingComputerAccount parameter to DSC_Computer#462Daymarvi wants to merge 4 commits into
Conversation
Add a new parameter DeleteExistingComputerAccount (default: true) to control whether an existing AD computer account is deleted and recreated when joining a domain. Setting it to false preserves the existing account (SID, group memberships, GPO links).
- Added entry in CHANGELOG.md under Unreleased/Added section - Fixed schema.mof description to reflect default value (true) - Added example 8: JoinDomainKeepExistingAccount_Config
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughA new ChangesDSC_Computer DeleteExistingComputerAccount Feature
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related issues
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 4
🤖 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 `@CHANGELOG.md`:
- Around line 10-14: The Computer section entry describing the
DeleteExistingComputerAccount parameter is missing a required issue reference
link. Add an issue reference to the end of this changelog entry using the
required format [issue
#<issue_number>](https://github.com/<owner>/<repo>/issues/<issue_number>) where
you replace the placeholder values with the actual GitHub issue number and
repository details that correspond to this feature addition.
In `@source/DSCResources/DSC_Computer/DSC_Computer.psm1`:
- Around line 101-104: The DeleteExistingComputerAccount parameter is declared
in the function signature but is missing from the hashtable returned by
Get-TargetResource. Add the DeleteExistingComputerAccount property to the
returned hashtable in Get-TargetResource (around lines 126-136) and set it to
the current value of the $DeleteExistingComputerAccount variable to maintain the
complete resource contract and match the declared schema.
- Around line 294-297: The Write-Verbose message using the
KeepingExistingComputerObject localized string in the else block (when
DeleteExistingComputerAccount is false) implies that an AD account lookup or
discovery occurred, but this branch skips AD queries entirely. Update the
verbose message to accurately reflect that the existing computer object is being
retained without claiming any AD discovery or verification took place, ensuring
the message content matches the actual behavior when the account lookup is
bypassed.
In `@source/DSCResources/DSC_Computer/en-US/DSC_Computer.strings.psd1`:
- Line 20: The KeepingExistingComputerObject message string incorrectly asserts
that an existing computer account was "found in domain" when this message is
actually used in a code path where no AD query is performed. Update the string
to remove the misleading "found in domain" phrase and instead describe what is
actually happening - that the existing account is being kept because
DeleteExistingComputerAccount is set to false, without implying that any domain
lookup or verification was performed.
🪄 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: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 1bf98980-2e57-4228-a777-8fff6b703413
📒 Files selected for processing (7)
CHANGELOG.mdsource/DSCResources/DSC_Computer/DSC_Computer.psm1source/DSCResources/DSC_Computer/DSC_Computer.schema.mofsource/DSCResources/DSC_Computer/README.mdsource/DSCResources/DSC_Computer/en-US/DSC_Computer.strings.psd1source/Examples/Resources/Computer/8-Computer_JoinDomainKeepExistingAccount_Config.ps1tests/Unit/DSC_Computer.Tests.ps1
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #462 +/- ##
===================================
Coverage 86% 87%
===================================
Files 21 21
Lines 2083 2086 +3
===================================
+ Hits 1805 1825 +20
+ Misses 278 261 -17
🚀 New features to boost your workflow:
|
- Add issue dsccommunity#457 reference to CHANGELOG entry - Return DeleteExistingComputerAccount from Get-TargetResource hashtable - Rename verbose message to SkippingExistingComputerObjectDeletion (no false AD discovery claim)
Pull Request (PR) description
When joining a domain,
DSC_Computercurrently deletes and recreates any existing AD computer account with the same name (Get-ADSIComputer+Remove-ADSIObject). This is destructive because it:Changes the machine SID, breaking existing Kerberos trust relationships
Loses AD group memberships assigned to the computer account
Loses GPO links specific to the computer object
Loses AD attributes (description, managedBy, etc.)
This PR adds a new
DeleteExistingComputerAccountparameter (Boolean) to control this behavior:$true(default)$falseAdd-Computerreuses the existing account (resets machine password only), preserving SID, group memberships, and GPO linksExample usage
Computer JoinDomain { Name = 'Server01' DomainName = 'Contoso' Credential = $Credential DeleteExistingComputerAccount = $false # Preserve existing AD computer account }This Pull Request (PR) fixes the following issues
Fixes #457
Task list
file CHANGELOG.md. Entry should say what was changed and how that
affects users (if applicable), and reference the issue being resolved
(if applicable).
and comment-based help.
This change is