From 2dad3eee643c51179b3238a7931ee75c09a90d36 Mon Sep 17 00:00:00 2001 From: fukusuket <41001169+fukusuket@users.noreply.github.com> Date: Sun, 13 Apr 2025 22:10:31 +0900 Subject: [PATCH] refactor --- WELA.ps1 | 56 ++++++++++++++++++++------------------------------------ 1 file changed, 20 insertions(+), 36 deletions(-) diff --git a/WELA.ps1 b/WELA.ps1 index 9060d831..eee6958d 100644 --- a/WELA.ps1 +++ b/WELA.ps1 @@ -984,6 +984,26 @@ function AuditLogSetting { $_.SetApplicable($enabledguid) $_.CountByLevel() } + + $auditResult | ForEach-Object { + $_ | Add-Member -MemberType NoteProperty -Name RuleCount -Value 0 + $_.RuleCount = ($_.Rules | Measure-Object).Count + $_ | Add-Member -MemberType NoteProperty -Name RuleCountByLevel -Value "" + $ruleCounts = "" + foreach ($level in [WELA]::Levels) { + $count = $_.RulesCount[$level] + if ($level -eq "informational") { + if (-not $count) { + $count = 0 + } + $ruleCounts += "info:$([string]$count)" + } else { + $ruleCounts += "$($level):$($count), " + } + } + $_.RuleCountByLevel = $ruleCounts + } + if ($outType -eq "std") { $auditResult | Group-Object -Property Category | ForEach-Object { $enabledCount = ($_.Group | Where-Object { $_.Enabled -eq $false }).Count -eq 0 @@ -1011,45 +1031,9 @@ function AuditLogSetting { } Write-Host "" } - $auditResult | ForEach-Object { - $_ | Add-Member -MemberType NoteProperty -Name RuleCount -Value 0 - $_.RuleCount = ($_.Rules | Measure-Object).Count - $_ | Add-Member -MemberType NoteProperty -Name RuleCountByLevel -Value "" - $ruleCounts = "" - foreach ($level in [WELA]::Levels) { - $count = $_.RulesCount[$level] - if ($level -eq "informational") { - if (-not $count) { - $count = 0 - } - $ruleCounts += "info:$([string]$count)" - } else { - $ruleCounts += "$($level):$($count), " - } - } - $_.RuleCountByLevel = $ruleCounts - } $auditResult | Select-Object -Property Category, SubCategory, TotalRules, TotalRuleByLevel, Enabled, DefaultSetting, RecommendedSetting, Volume, Note | Export-Csv -Path "WELA-Audit-Result.csv" -NoTypeInformation Write-Output "Audit check result saved to: WELA-Audit-Result.csv" } elseif ($outType -eq "gui") { - $auditResult | ForEach-Object { - $_ | Add-Member -MemberType NoteProperty -Name RuleCount -Value 0 - $_.RuleCount = ($_.Rules | Measure-Object).Count - $_ | Add-Member -MemberType NoteProperty -Name RuleCountByLevel -Value "" - $ruleCounts = "" - foreach ($level in [WELA]::Levels) { - $count = $_.RulesCount[$level] - if ($level -eq "informational") { - if (-not $count) { - $count = 0 - } - $ruleCounts += "info:$([string]$count)" - } else { - $ruleCounts += "$($level):$($count), " - } - } - $_.RuleCountByLevel = $ruleCounts - } $auditResult | Select-Object -Property Category, SubCategory, RuleCount, RuleCountByLevel, Enabled, DefaultSetting, RecommendedSetting, Volume, Note | Out-GridView -Title "WELA Audit Result" } $usableRules = $auditResult | Select-Object -ExpandProperty Rules | Where-Object { $_.applicable -eq $true }