Skip to content

Commit 72b3ed5

Browse files
New-DbaLogin - Fix bug in PasswordMustChange (#9713)
1 parent d973ec0 commit 72b3ed5

File tree

3 files changed

+3
-5
lines changed

3 files changed

+3
-5
lines changed

public/New-DbaLogin.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ function New-DbaLogin {
532532
}
533533

534534
#Process the MustChangePassword property
535-
if ($currentPasswordMustChange -ne $newLogin.MustChangePassword) {
535+
if ($null -ne $currentPasswordMustChange -and $currentPasswordMustChange -ne $newLogin.MustChangePassword) {
536536
try {
537537
$newLogin.ChangePassword($SecurePassword, $true, $true)
538538
Write-Message -Level Verbose -Message "Login $loginName has been marked as must change password."

tests/New-DbaLogin.Tests.ps1

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" {
190190
It "Should not have same properties because of the overrides" {
191191

192192
$login1 = Get-DbaLogin -SqlInstance $TestConfig.instance1 -login claudio
193-
$login2 = Get-DbaLogin -SqlInstance $TestConfig.instance2 -login withMustChange
193+
$login2 = Get-DbaLogin -SqlInstance $TestConfig.instance2 -login claudio
194194

195195
$login2 | Should Not BeNullOrEmpty
196196

@@ -201,12 +201,11 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" {
201201
$login1.IsDisabled | Should Not be $login2.IsDisabled
202202
$login1.PasswordExpirationEnabled | Should Not be $login2.PasswordExpirationEnabled
203203
$login1.PasswordPolicyEnforced | Should Not be $login2.PasswordPolicyEnforced
204-
$login1.MustChangePassword | Should Not be $login2.MustChangePassword
205204
$login1.Sid | Should Not be $login2.Sid
206205
}
207206
if ($IsWindows -ne $false) {
208207
It "Should create a disabled account with deny Windows login" {
209-
$results = New-DbaLogin -SqlInstance $server1 -Login $winLogin -Disabled -DenyWindowsLogin
208+
$results = New-DbaLogin -SqlInstance $server1 -Login $winLogin -Disabled -DenyWindowsLogin -Force
210209
$results.Name | Should Be "$winLogin"
211210
$results.DefaultDatabase | Should be 'master'
212211
$results.IsDisabled | Should be $true

tests/pester.groups.ps1

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ $TestsRunGroups = @{
3535
'Dismount-DbaDatabase',
3636
# tests that fail locally against SQL Server 2022 instances and fail on AppVeyor
3737
'Set-DbaAgentJobStep',
38-
'New-DbaLogin',
3938
'Watch-DbaDbLogin',
4039
# tests that fail because the command does not work
4140
'Copy-DbaDbCertificate',

0 commit comments

Comments
 (0)