diff --git a/source/Private/Get-PhishPolicyCompliance.ps1 b/source/Private/Get-PhishPolicyCompliance.ps1 index 4208aa9..5d9300d 100644 --- a/source/Private/Get-PhishPolicyCompliance.ps1 +++ b/source/Private/Get-PhishPolicyCompliance.ps1 @@ -4,6 +4,7 @@ function Get-PhishPolicyCompliance { [Parameter(Mandatory = $true)] [PSCustomObject]$Policy ) + Write-Verbose "Starting compliance evaluation for policy: $($Policy.Name)" # Define the compliance criteria for an anti-phishing policy $complianceCriteria = @{ Enabled = $true # Policy must be enabled @@ -24,22 +25,33 @@ function Get-PhishPolicyCompliance { # Initialize compliance state and a list to track non-compliance reasons $isCompliant = $true $nonCompliantReasons = @() + Write-Verbose "Evaluating compliance criteria for policy: $($Policy.Name)" # Iterate through the compliance criteria and check each property of the policy foreach ($key in $complianceCriteria.Keys) { + Write-Verbose "Checking $key`: Expected $($complianceCriteria[$key])" if ($Policy.PSObject.Properties[$key] -and $Policy.$key -ne $complianceCriteria[$key]) { + Write-Verbose "Non-compliance detected for $key. Found $($Policy.$key)" $isCompliant = $false # Mark as non-compliant if the value doesn't match $nonCompliantReasons += "$key`: Expected $($complianceCriteria[$key]), Found $($Policy.$key)" # Record the discrepancy + } else { + Write-Verbose "$key is compliant." } } # Special case: Ensure PhishThresholdLevel is at least 3 + Write-Verbose "Checking PhishThresholdLevel: Expected at least 3" if ($Policy.PSObject.Properties['PhishThresholdLevel'] -and $Policy.PhishThresholdLevel -lt 3) { + Write-Verbose "Non-compliance detected for PhishThresholdLevel. Found $($Policy.PhishThresholdLevel)" $isCompliant = $false # Mark as non-compliant if threshold is below 3 $nonCompliantReasons += "PhishThresholdLevel: Expected at least 3, Found $($Policy.PhishThresholdLevel)" # Record the issue + } else { + Write-Verbose "PhishThresholdLevel is compliant." } # Log the reasons for non-compliance if the policy is not compliant if (-not $isCompliant) { Write-Verbose "Policy $($Policy.Name) is not compliant. Reasons: $($nonCompliantReasons -join '; ')" + } else { + Write-Verbose "Policy $($Policy.Name) is fully compliant." } # Return whether the policy is compliant return $isCompliant -} \ No newline at end of file +}