docs: fix test-environment scripts after first live run
Declare the service account DN before the OU loop and print the LDAP result code and server message when the password-change check fails. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01N3t4WL7bd9bdHHNjEsxzqC
This commit is contained in:
@@ -72,6 +72,7 @@ $domain = Get-ADDomain
|
|||||||
$netbios = $domain.NetBIOSName
|
$netbios = $domain.NetBIOSName
|
||||||
$testOuDn = "OU=$TestOuName,$ParentDn"
|
$testOuDn = "OU=$TestOuName,$ParentDn"
|
||||||
$svcOuDn = "OU=$ServiceOuName,$ParentDn"
|
$svcOuDn = "OU=$ServiceOuName,$ParentDn"
|
||||||
|
$svcDn = "CN=$ServiceAccountName,$svcOuDn"
|
||||||
$real = -not $WhatIfPreference
|
$real = -not $WhatIfPreference
|
||||||
$secrets = [ordered]@{}
|
$secrets = [ordered]@{}
|
||||||
$groups = @{}
|
$groups = @{}
|
||||||
@@ -89,7 +90,6 @@ foreach ($ou in @(@($TestOuName, $testOuDn), @($ServiceOuName, $svcOuDn))) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# --- service account (outside the test OU on purpose) ------------------------
|
# --- service account (outside the test OU on purpose) ------------------------
|
||||||
$svcDn = "CN=$ServiceAccountName,$svcOuDn"
|
|
||||||
if (Test-Dn $svcDn) {
|
if (Test-Dn $svcDn) {
|
||||||
Write-Host "Service account exists: $svcDn (password unchanged)"
|
Write-Host "Service account exists: $svcDn (password unchanged)"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -134,7 +134,13 @@ if ($TestPasswordChange) {
|
|||||||
$add.Name = 'unicodePwd'; $add.Operation = 'Add'; [void]$add.Add($enc.GetBytes('"' + $newPw + '"'))
|
$add.Name = 'unicodePwd'; $add.Operation = 'Add'; [void]$add.Add($enc.GetBytes('"' + $newPw + '"'))
|
||||||
$ok = $true; $detail = ''
|
$ok = $true; $detail = ''
|
||||||
try { [void]$conn.SendRequest((New-Object System.DirectoryServices.Protocols.ModifyRequest($userDn, @($del, $add)))) }
|
try { [void]$conn.SendRequest((New-Object System.DirectoryServices.Protocols.ModifyRequest($userDn, @($del, $add)))) }
|
||||||
catch { $ok = $false; $detail = $_.Exception.Message }
|
catch {
|
||||||
|
$ok = $false; $detail = $_.Exception.Message
|
||||||
|
$inner = $_.Exception.InnerException
|
||||||
|
if ($inner -is [System.DirectoryServices.Protocols.DirectoryOperationException]) {
|
||||||
|
$detail += " [LDAP result: $($inner.Response.ResultCode); server: $($inner.Response.ErrorMessage)]"
|
||||||
|
}
|
||||||
|
}
|
||||||
Report 'change a password with the Change Password right' $ok $detail
|
Report 'change a password with the Change Password right' $ok $detail
|
||||||
}
|
}
|
||||||
else { Write-Host 'SKIP password change (use -TestPasswordChange; it changes the test user password)' -ForegroundColor Yellow }
|
else { Write-Host 'SKIP password change (use -TestPasswordChange; it changes the test user password)' -ForegroundColor Yellow }
|
||||||
|
|||||||
Reference in New Issue
Block a user