Skip to content

Commit a90b6ca

Browse files
committed
fix: improve module logging path checks in WELA.ps1
1 parent a6fba5d commit a90b6ca

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

WELA.ps1

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5717,7 +5717,8 @@ function ConfigureAuditSettings {
57175717
try {
57185718
$moduleLoggingPath = "HKLM:\SOFTWARE\Wow6432Node\Policies\Microsoft\Windows\PowerShell\ModuleLogging\ModuleNames"
57195719
$currentValue = "Not Set"
5720-
if (Test-Path $moduleLoggingPath) {
5720+
$pathExists = Test-Path $moduleLoggingPath
5721+
if ($pathExists) {
57215722
$prop = Get-ItemProperty -Path $moduleLoggingPath -Name "*" -ErrorAction SilentlyContinue
57225723
if ($prop) {
57235724
$currentValue = $prop."*"
@@ -5739,7 +5740,10 @@ function ConfigureAuditSettings {
57395740
}
57405741
if ($response -eq "" -or $response -eq "Y" -or $response -eq "y")
57415742
{
5742-
New-Item -Path $moduleLoggingPath -Force | Out-Null
5743+
if (-not $pathExists)
5744+
{
5745+
New-Item -Path $moduleLoggingPath -Force | Out-Null
5746+
}
57435747
Set-ItemProperty -Path $moduleLoggingPath -Name "*" -Value "*" -Type String
57445748
Write-Host "[OK] Module logging enabled for all modules" -ForegroundColor Green
57455749
}

0 commit comments

Comments
 (0)