fix: 1.3.1 aligned with test-template

This commit is contained in:
DrIOS
2024-05-28 13:17:11 -05:00
parent 398ce397f5
commit 3883e33a4a

View File

@@ -1,45 +1,54 @@
function Test-PasswordNeverExpirePolicy { function Test-PasswordNeverExpirePolicy {
[CmdletBinding()] [CmdletBinding()]
param ( param (
# Aligned
[Parameter(Mandatory)] [Parameter(Mandatory)]
[string]$DomainName # DomainName parameter is now mandatory [string]$DomainName # DomainName parameter is now mandatory
) )
begin { begin {
# Dot source the class script # Dot source the class script if necessary
#. .\source\Classes\CISAuditResult.ps1
$auditResults = @() # Initialization code, if needed
} }
process { process {
# 1.3.1 (L1) Ensure the 'Password expiration policy' is set to 'Set passwords to never expire' # 1.3.1 (L1) Ensure the 'Password expiration policy' is set to 'Set passwords to never expire'
# Pass if PasswordValidityPeriodInDays is 0. # Pass if PasswordValidityPeriodInDays is 0. Fail otherwise.
# Fail otherwise.
$passwordPolicy = Get-MgDomain -DomainId $DomainName | Select-Object PasswordValidityPeriodInDays # Retrieve password expiration policy
$passwordPolicy = Get-MgDomain -DomainId $DomainName | Select-Object -ExpandProperty PasswordValidityPeriodInDays
# Create an instance of CISAuditResult and populate it # Prepare failure reasons and details based on compliance
$failureReasons = if ($passwordPolicy -ne 0) {
"Password expiration is not set to never expire"
}
else {
"N/A"
}
$details = "Validity Period: $passwordPolicy days"
# Create and populate the CISAuditResult object
$auditResult = [CISAuditResult]::new() $auditResult = [CISAuditResult]::new()
$auditResult.Rec = "1.3.1" $auditResult.Status = if ($passwordPolicy -eq 0) { "Pass" } else { "Fail" }
$auditResult.RecDescription = "Ensure the 'Password expiration policy' is set to 'Set passwords to never expire'"
$auditResult.ELevel = "E3" $auditResult.ELevel = "E3"
$auditResult.ProfileLevel = "L1" $auditResult.ProfileLevel = "L1"
$auditResult.Rec = "1.3.1"
$auditResult.RecDescription = "Ensure the 'Password expiration policy' is set to 'Set passwords to never expire'"
$auditResult.CISControlVer = "v8" $auditResult.CISControlVer = "v8"
$auditResult.CISControl = "5.2" $auditResult.CISControl = "5.2"
$auditResult.CISDescription = "Use Unique Passwords" $auditResult.CISDescription = "Use Unique Passwords"
$auditResult.IG1 = $true $auditResult.IG1 = $true
$auditResult.IG2 = $true $auditResult.IG2 = $true
$auditResult.IG3 = $true # All are true $auditResult.IG3 = $true
$auditResult.Result = $passwordPolicy.PasswordValidityPeriodInDays -eq 0 $auditResult.Result = $passwordPolicy -eq 0
$auditResult.Details = "Validity Period: $($passwordPolicy.PasswordValidityPeriodInDays) days" $auditResult.Details = $details
$auditResult.FailureReason = if ($passwordPolicy.PasswordValidityPeriodInDays -eq 0) { "N/A" } else { "Password expiration is not set to never expire" } $auditResult.FailureReason = $failureReasons
$auditResult.Status = if ($passwordPolicy.PasswordValidityPeriodInDays -eq 0) { "Pass" } else { "Fail" }
$auditResults += $auditResult
} }
end { end {
# Return auditResults # Return the audit result
return $auditResults return $auditResult
} }
} }