Skip to content

Commit f424ee2

Browse files
seunggabiseunggabiclaude
authored
(#30) fix: scheduled task path concatenation, function names, and Count error (#31)
- Use $moduleFilePath instead of overwriting $modulePath in foreach loop - Add function name mapping matching bin/win-ops.ps1 conventions - Wrap Where-Object results in @() to prevent $null.Count under strict mode Co-authored-by: seunggabi <seung@DESKTOP-HD7MPE5.localdomain> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent bf90ec4 commit f424ee2

1 file changed

Lines changed: 25 additions & 8 deletions

File tree

scheduler/Invoke-WinOpsScheduled.ps1

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,23 @@ try {
6969
Write-WinOpsLog -Level INFO -Message "Taking system snapshot (before)"
7070
$snapshotBefore = Get-WinOpsSnapshot -IncludeDisk -IncludeMemory
7171

72+
# Module name to function name mapping
73+
$functionMap = @{
74+
'CacheCleanup' = 'Clear-WinOpsCache'
75+
'TmpCleanup' = 'Clear-WinOpsTempFiles'
76+
'LogCleanup' = 'Clear-WinOpsLogFiles'
77+
'MemoryCleanup' = 'Clear-WinOpsMemory'
78+
'RegistryCleanup' = 'Clear-WinOpsRegistry'
79+
'HistoryCleanup' = 'Clear-WinOpsHistory'
80+
'OrphanAppCleanup' = 'Clear-WinOpsOrphanedAppData'
81+
'BrowserCleanup' = 'Clear-WinOpsBrowserData'
82+
'DevCleanup' = 'Invoke-WinOpsDevCleanup'
83+
'DockerCleanup' = 'Clear-WinOpsDockerResources'
84+
'PackageManagerCleanup' = 'Clear-WinOpsPackageManagerCache'
85+
'ZombieKiller' = 'Invoke-WinOpsZombieCleanup'
86+
'OrphanKiller' = 'Invoke-WinOpsOrphanCleanup'
87+
}
88+
7289
# Execute cleanup modules based on configuration
7390
$results = @()
7491
$totalFreed = 0
@@ -84,17 +101,17 @@ try {
84101
Write-WinOpsLog -Level INFO -Message "Executing module: $($module.Name)"
85102

86103
# Import module
87-
$modulePath = Join-Path $modulePath "lib\modules\$($module.Name).psm1"
104+
$moduleFilePath = Join-Path $modulePath "lib\modules\$($module.Name).psm1"
88105

89-
if (-not (Test-Path $modulePath)) {
90-
Write-WinOpsLog -Level WARN -Message "Module file not found: $modulePath"
106+
if (-not (Test-Path $moduleFilePath)) {
107+
Write-WinOpsLog -Level WARN -Message "Module file not found: $moduleFilePath"
91108
continue
92109
}
93110

94-
Import-Module $modulePath -Force
111+
Import-Module $moduleFilePath -Force
95112

96-
# Execute cleanup function
97-
$functionName = "Clear-WinOps$($module.Name)"
113+
# Execute cleanup function (use mapping, fallback to convention)
114+
$functionName = if ($functionMap.ContainsKey($module.Name)) { $functionMap[$module.Name] } else { "Clear-WinOps$($module.Name)" }
98115

99116
if (-not (Get-Command $functionName -ErrorAction SilentlyContinue)) {
100117
Write-WinOpsLog -Level WARN -Message "Function $functionName not found"
@@ -177,8 +194,8 @@ try {
177194

178195
# Generate summary
179196
$totalFreedGB = [math]::Round($totalFreed / 1GB, 2)
180-
$successCount = ($results | Where-Object { $_.Success }).Count
181-
$failureCount = ($results | Where-Object { -not $_.Success }).Count
197+
$successCount = @($results | Where-Object { $_.Success }).Count
198+
$failureCount = @($results | Where-Object { -not $_.Success }).Count
182199

183200
$summary = @"
184201
Win-Ops Scheduled Cleanup Summary

0 commit comments

Comments
 (0)