Disable reversible password storage for SGU accounts

This commit is contained in:
alexrg committed 2026-09-29 12:00:36 -06:00
1 parent 80baae1b54
commit 414a08ece6
9 files changed
+61 -46

No files matched your search

+11 -11
View File
@@ -35,7 +35,7 @@ foreach ($groupDn in $groups) {
$desired = @{
Precedence = $Precedence
ComplexityEnabled = $false
ReversibleEncryptionEnabled = $true
ReversibleEncryptionEnabled = $false
MinPasswordLength = 1
PasswordHistoryCount = 0
MinPasswordAge = [TimeSpan]::Zero
@@ -51,7 +51,7 @@ $policy = Get-ADFineGrainedPasswordPolicy -Filter * -Server $DomainController |
if (-not $policy) {
if ($PSCmdlet.ShouldProcess($PolicyName, 'Create password policy limited to SGU role groups')) {
New-ADFineGrainedPasswordPolicy -Name $PolicyName @desired -Server $DomainController `
-Description 'SGU validates the exact institutional password; reversible storage is enabled only for SGU role groups, and AD must not reject its complexity, length, history, or age.' `
-Description 'SGU validates the exact institutional password; reversible storage remains disabled and AD must not reject its complexity, length, history, or age.' `
-ProtectedFromAccidentalDeletion $true | Out-Null
}
}
@@ -80,10 +80,10 @@ foreach ($groupDn in $groups) {
}
}
# Existing SGU group members also need the per-account UAC bit before the next
# broker SetPassword call. The default domain policy stays unchanged, and users
# outside these three SGU groups are deliberately excluded.
$reversibleAccountsEnabled = 0
# Existing SGU group members must have the per-account UAC bit cleared as well.
# The default domain policy stays unchanged, and users outside these three SGU
# groups are deliberately excluded.
$reversibleAccountsDisabled = 0
$usersOuDn = "OU=Usuarios-SGU,$BaseDn"
$managedUserDns = [Collections.Generic.HashSet[string]]::new([StringComparer]::OrdinalIgnoreCase)
foreach ($groupDn in $groups) {
@@ -100,11 +100,11 @@ foreach ($userDn in $managedUserDns) {
if (-not $user.DistinguishedName.EndsWith(",$usersOuDn", [StringComparison]::OrdinalIgnoreCase)) {
continue
}
if (-not $user.AllowReversiblePasswordEncryption -and
$PSCmdlet.ShouldProcess($user.SamAccountName, 'Allow reversible password storage for SGU account')) {
if ($user.AllowReversiblePasswordEncryption -and
$PSCmdlet.ShouldProcess($user.SamAccountName, 'Disable reversible password storage for SGU account')) {
Set-ADAccountControl -Identity $user.DistinguishedName `
-AllowReversiblePasswordEncryption $true -Server $DomainController -Confirm:$false
$reversibleAccountsEnabled++
-AllowReversiblePasswordEncryption $false -Server $DomainController -Confirm:$false
$reversibleAccountsDisabled++
}
}
@@ -131,6 +131,6 @@ if (-not $WhatIfPreference) {
MinPasswordLength = $policy.MinPasswordLength
PasswordHistoryCount = $policy.PasswordHistoryCount
MaxPasswordAge = $policy.MaxPasswordAge
ExistingAccountFlagsEnabled = $reversibleAccountsEnabled
ExistingAccountFlagsDisabled = $reversibleAccountsDisabled
Subjects = @($policy.AppliesTo)
}