Skip to content

Commit

Permalink
Updated 'Set-TargetResource' in 'SqlLogin' to update 'PasswordPolicyE…
Browse files Browse the repository at this point in the history
…nforced' and 'PasswordExpirationEnabled' as a single update.
  • Loading branch information
SphenicPaul committed Jan 11, 2021
1 parent d2db2e0 commit d0d0120
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions source/DSCResources/DSC_SqlLogin/DSC_SqlLogin.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -201,25 +201,20 @@ function Set-TargetResource
New-InvalidOperationException -Message $errorMessage
}

# This must always be updated before `PasswordExpirationEnabled`
if ( $login.PasswordPolicyEnforced -ne $LoginPasswordPolicyEnforced )
# `PasswordPolicyEnforced and `PasswordExpirationEnabled` must be updated together (if one or both are not in the desired state)
if ( $login.PasswordPolicyEnforced -ne $LoginPasswordPolicyEnforced -or
$login.PasswordExpirationEnabled -ne $LoginPasswordExpirationEnabled )
{
Write-Verbose -Message (
$script:localizedData.SetPasswordPolicyEnforced -f $LoginPasswordPolicyEnforced, $Name, $ServerName, $InstanceName
)

$login.PasswordPolicyEnforced = $LoginPasswordPolicyEnforced
Update-SQLServerLogin -Login $login
}

# This must always be updated after `PasswordPolicyEnforced`
if ( $login.PasswordExpirationEnabled -ne $LoginPasswordExpirationEnabled )
{
Write-Verbose -Message (
$script:localizedData.SetPasswordExpirationEnabled -f $LoginPasswordExpirationEnabled, $Name, $ServerName, $InstanceName
)

$login.PasswordPolicyEnforced = $LoginPasswordPolicyEnforced
$login.PasswordExpirationEnabled = $LoginPasswordExpirationEnabled

Update-SQLServerLogin -Login $login
}

Expand Down

0 comments on commit d0d0120

Please sign in to comment.