Skip to content

Commit 6d1ebe0

Browse files
so we check password expirations
1 parent 21110c1 commit 6d1ebe0

File tree

2 files changed

+43
-29
lines changed

2 files changed

+43
-29
lines changed

source/checks/Instancev5.Tests.ps1

+9
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,15 @@ Describe "Login Must Change" -Tag LoginMustChange, Security, CIS, Medium, Instan
236236
}
237237
}
238238

239+
Describe "Login Password Expiration" -Tag LoginPasswordExpiration, Security, CIS, Medium, Instance -ForEach $InstancesToTest {
240+
$skip = ($__dbcconfig | Where-Object { $_.Name -eq 'skip.security.LoginPasswordExpiration' }).Value
241+
Context "Testing if the login password expiration is enabled for sql logins in the sysadmin role on <_.Name>" {
242+
It "All sql logins should have the password expiration option set to ON in the sysadmin role on <_.Name>" -Skip:$skip {
243+
$PsItem.LoginPasswordExpirationCount | Should -Be 0 -Because "We expected the password expiration policy to set on all sql logins in the sysadmin role"
244+
}
245+
}
246+
}
247+
239248
Describe "Instance MaxDop" -Tag MaxDopInstance, MaxDop, Medium, Instance -ForEach ($InstancesToTest | Where-Object { $psitem.Name -notin $psitem.ConfigValues.ExcludeInstanceMaxDop }) {
240249
$skip = ($__dbcconfig | Where-Object { $_.Name -eq 'skip.instance.MaxDopInstance' }).Value
241250
Context "Testing Instance MaxDop Value on <_.Name>" {

source/internal/functions/NewGet-AllInstanceInfo.ps1

+34-29
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,11 @@ function NewGet-AllInstanceInfo {
467467
$lastlogin = @{Name = 'LastLogin' ; Expression = { $Name = $_.name; ($loginTimes | Where-Object { $_.login_name -eq $name }).login_time
468468
}
469469
}
470-
$LoginMustChangeCount = ($Instance.Logins | Where-Object { $_.Name -in $Instance.Roles['sysadmin'].EnumMemberNames() } | Select-Object Name, $lastlogin, MustChangePassword, IsDisabled | Where-Object { $_.MustChangePassword -eq $false -and $_.IsDisabled -eq $false -and $null -eq $_.LastLogin }).Count
470+
$LoginMustChangeCount = ($Instance.Logins | Where-Object { $_.LoginType -eq 'SqlLogin' } | Where-Object { $_.Name -in $Instance.Roles['sysadmin'].EnumMemberNames() } | Select-Object Name, $lastlogin, MustChangePassword, IsDisabled | Where-Object { $_.MustChangePassword -eq $false -and $_.IsDisabled -eq $false -and $null -eq $_.LastLogin }).Count
471+
}
472+
473+
'LoginPasswordExpiration' {
474+
$LoginPasswordExpirationCount = ($Instance.Logins | Where-Object { $_.Name -in $Instance.Roles['sysadmin'].EnumMemberNames() } | Where-Object { $_.LoginType -eq 'SqlLogin' -and $_.PasswordExpirationEnabled -EQ $false -and $_.IsDisabled -EQ $false }).Count
471475
}
472476

473477
Default { }
@@ -476,20 +480,20 @@ function NewGet-AllInstanceInfo {
476480
#build the object
477481

478482
$testInstanceObject = [PSCustomObject]@{
479-
ComputerName = $Instance.ComputerName
480-
InstanceName = $Instance.DbaInstanceName
481-
Name = $Instance.Name
482-
ConfigValues = $ConfigValues
483-
VersionMajor = $Instance.VersionMajor
484-
Configuration = if ($configurations) { $Instance.Configuration } else { $null }
485-
Settings = $Instance.Settings
486-
Logins = $Instance.Logins
487-
Databases = $Instance.Databases
488-
NumberOfLogFiles = $Instance.NumberOfLogFiles
489-
MaxDopSettings = $MaxDopSettings
490-
ExpectedTraceFlags = $ExpectedTraceFlags
491-
NotExpectedTraceFlags = $NotExpectedTraceFlags
492-
XESessions = [pscustomobject]@{
483+
ComputerName = $Instance.ComputerName
484+
InstanceName = $Instance.DbaInstanceName
485+
Name = $Instance.Name
486+
ConfigValues = $ConfigValues
487+
VersionMajor = $Instance.VersionMajor
488+
Configuration = if ($configurations) { $Instance.Configuration } else { $null }
489+
Settings = $Instance.Settings
490+
Logins = $Instance.Logins
491+
Databases = $Instance.Databases
492+
NumberOfLogFiles = $Instance.NumberOfLogFiles
493+
MaxDopSettings = $MaxDopSettings
494+
ExpectedTraceFlags = $ExpectedTraceFlags
495+
NotExpectedTraceFlags = $NotExpectedTraceFlags
496+
XESessions = [pscustomobject]@{
493497
RequiredStopped = $RequiredStopped.ForEach{
494498
[pscustomobject]@{
495499
Name = $Instance.Name
@@ -524,23 +528,23 @@ function NewGet-AllInstanceInfo {
524528
Sessions = $Sessions
525529
Running = $RunningSessions
526530
}
527-
ErrorLogEntries = [pscustomobject]@{
531+
ErrorLogEntries = [pscustomobject]@{
528532
errorLogCount = $ErrorLogCount
529533
logWindow = $logWindow
530534
}
531-
InstanceConnection = $InstanceConnection
532-
BackupPathAccess = [pscustomobject]@{
535+
InstanceConnection = $InstanceConnection
536+
BackupPathAccess = [pscustomobject]@{
533537
Result = $BackupPathAccess
534538
BackupPath = $BackupPath
535539
}
536-
LatestBuild = [PSCustomObject]@{
540+
LatestBuild = [PSCustomObject]@{
537541
Compliant = $LatestBuild.Compliant
538542
}
539-
NetworkLatency = [PSCustomObject]@{
543+
NetworkLatency = [PSCustomObject]@{
540544
Latency = $Latency
541545
Threshold = $NetworkThreshold
542546
}
543-
LinkedServerResults = if ($LinkedServerResults) {
547+
LinkedServerResults = if ($LinkedServerResults) {
544548
$LinkedServerResults.ForEach{
545549
[pscustomobject]@{
546550
InstanceName = $Instance.Name
@@ -559,20 +563,21 @@ function NewGet-AllInstanceInfo {
559563
Result = 'None'
560564
}
561565
}
562-
MaxMemory = $MaxMemory
563-
OrphanedFile = [pscustomobject]@{
566+
MaxMemory = $MaxMemory
567+
OrphanedFile = [pscustomobject]@{
564568
FileCount = $FileCount
565569
}
566-
ServerNameMatch = [pscustomobject]@{
570+
ServerNameMatch = [pscustomobject]@{
567571
configuredServerName = $ServerNameMatchconfiguredServerName
568572
netName = $ServerNameMatchnetName
569573
renamerequired = $ServerNameMatchrenamerequired
570574
}
571-
MemoryDump = $Dump
572-
HideInstance = $HideInstance
573-
SuspectPageCountResult = $SuspectPageCountResult
574-
SupportedBuild = $SupportedBuild
575-
LoginMustChangeCount = $LoginMustChangeCount
575+
MemoryDump = $Dump
576+
HideInstance = $HideInstance
577+
SuspectPageCountResult = $SuspectPageCountResult
578+
SupportedBuild = $SupportedBuild
579+
LoginMustChangeCount = $LoginMustChangeCount
580+
LoginPasswordExpirationCount = $LoginPasswordExpirationCount
576581
# TempDbConfig = [PSCustomObject]@{
577582
# TF118EnabledCurrent = $tempDBTest[0].CurrentSetting
578583
# TF118EnabledRecommended = $tempDBTest[0].Recommended

0 commit comments

Comments
 (0)