Separate detection from repair

Detection should be read-only and fast. Remediation should validate preconditions, make one targeted change, and emit a useful result. This separation makes failures diagnosable and prevents a repair script from masking drift.

Use guardrails

Check operating system, service state, and required registry paths before changing anything. Log the old and new state without writing secrets or personal data.

$key = 'HKLM:\SOFTWARE\Contoso\Baseline'
$current = (Get-ItemProperty $key -ErrorAction SilentlyContinue).Version
if ($current -ne '2026.09') {
  Set-ItemProperty -Path $key -Name Version -Value '2026.09'
}
Write-Output "BaselineVersion=$((Get-ItemProperty $key).Version)"

Measure the outcome

Track detection rate, remediation success, retry count, and the most common failure reason. Compliance improves when the team can distinguish an endpoint that is fixed from one that is unreachable or excluded.

Operational checklist

  • Keep detection read-only.
  • Validate preconditions before repair.
  • Make the change idempotent.
  • Return evidence that an operator can act on.

Related technical articles