Skip to content

Add VixTemp folder cleanup script for dental imaging workstations#40

Open
AlrightLad wants to merge 2 commits intoDTC-Inc:mainfrom
AlrightLad:patch-3
Open

Add VixTemp folder cleanup script for dental imaging workstations#40
AlrightLad wants to merge 2 commits intoDTC-Inc:mainfrom
AlrightLad:patch-3

Conversation

@AlrightLad
Copy link

@AlrightLad AlrightLad commented Jan 30, 2026

Automated cleanup script for C:\vixtemp folder used by Vixwin/Dentimax/Curve dental imaging sensors. Prevents sensor failures when folder exceeds 250MB.

Features

  • Archives oldest files when folder exceeds 250MB threshold
  • Targets 200MB post-cleanup (50MB buffer)
  • Maintains 5 rotating archive versions for image recovery
  • Server detection - only runs on workstations
  • Concurrent execution prevention via lock file
  • Ninja RMM alerting via Windows Event Log (Event IDs 1000-1002)
  • Dual logging (transcript + daily logs) for troubleshooting
  • Disk space pre-check with 150% safety buffer
  • Gracefully skips locked files

Deployment

  • Designed for Ninja RMM scheduled task (every 4 hours)
  • Runs as SYSTEM
  • Self-determining: safe to deploy broadly (exits silently on servers or machines without C:\vixtemp)

Paths

  • Source: C:\vixtemp
  • Archives: C:\vixtemp_archives
  • Logs: C:\ProgramData\VixTempCleanup\Logs

Testing

  • Tested on Windows 10/11 workstations
  • Validated with 32-bit PowerShell (uses Compress-Archive for compatibility)

Summary by CodeRabbit

Release Notes

  • New Features
    • Introduced an automated temporary folder cleanup utility that monitors disk usage and archives oldest files when configurable thresholds are exceeded.
    • Supports both scheduled (RMM) and interactive execution modes.
    • Includes comprehensive logging, archive management, and overdue cleanup notifications.

✏️ Tip: You can customize this high-level summary in your review settings.

Automated cleanup script for C:\vixtemp folder used by Vixwin/Dentimax/Curve
dental imaging sensors. Prevents sensor failures when folder exceeds 250MB.

## Features
- Archives oldest files when folder exceeds 250MB threshold
- Targets 200MB post-cleanup (50MB buffer)
- Maintains 5 rotating archive versions for image recovery
- Server detection - only runs on workstations
- Concurrent execution prevention via lock file
- Ninja RMM alerting via Windows Event Log (Event IDs 1000-1002)
- Dual logging (transcript + daily logs) for troubleshooting
- Disk space pre-check with 150% safety buffer
- Gracefully skips locked files

## Deployment
- Designed for Ninja RMM scheduled task (every 4 hours)
- Runs as SYSTEM
- Self-determining: safe to deploy broadly (exits silently on servers or machines without C:\vixtemp)

## Paths
- Source: C:\vixtemp
- Archives: C:\vixtemp_archives
- Logs: C:\ProgramData\VixTempCleanup\Logs

## Testing
- Tested on Windows 10/11 workstations
- Validated with 32-bit PowerShell (uses Compress-Archive for compatibility)
@AlrightLad AlrightLad requested a review from Gumbees as a code owner January 30, 2026 05:42
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 30, 2026

Warning

Rate limit exceeded

@AlrightLad has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 1 minutes and 8 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📝 Walkthrough

Walkthrough

A new PowerShell script that monitors C:\vixtemp and automatically archives oldest files when folder size exceeds a configured threshold. Features include lock-based concurrency control, configurable retention policies, logging with optional event log alerts, and workstation-only operation.

Changes

Cohort / File(s) Summary
VixTempCleanup Script
rmm-misc/VixWinTempFolderCleanup.ps1
New 648-line PowerShell script implementing folder monitoring, file archival, and cleanup with lock file management, disk space validation, archive rotation, log rotation, and Ninja alert integration. Includes 20 helper functions covering initialization, logging, server detection, locking, disk checks, archiving, rotation, and overdue notifications.

Sequence Diagram

sequenceDiagram
    participant User
    participant Script
    participant Monitor as Folder Monitor
    participant Lock as Lock Manager
    participant Disk as Disk Space Check
    participant Archive as Archive Creator
    participant Cleanup as File Cleanup
    participant Log as Logger & Alerts

    User->>Script: Execute script
    Script->>Script: Initialize directories
    Script->>Monitor: Check if server OS
    alt Server detected
        Script->>Log: Exit early
    else Workstation
        Script->>Lock: Acquire lock file
        alt Lock obtained
            Script->>Monitor: Check folder size
            alt Size exceeds threshold
                Script->>Monitor: Identify oldest files
                Script->>Disk: Verify sufficient disk space
                alt Space available
                    Script->>Archive: Create ZIP archive
                    Script->>Cleanup: Delete archived files
                    Script->>Cleanup: Prune empty directories
                    Script->>Cleanup: Rotate old archives
                    Script->>Log: Log success
                else Insufficient space
                    Script->>Log: Log failure & alert
                end
            else Size under threshold
                Script->>Log: Log as skipped
            end
            Script->>Lock: Release lock file
        else Lock conflict
            Script->>Log: Exit with lock error
        end
    end
    Script->>Log: Close transcript
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Poem

🐰 A rabbit's joy: old vix files now tidy and stacked,
Archived away in zips, with locks intact,
Diskspace protected, logs rolling through,
C:\vixtemp cleaned up, fresh as morning dew! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: a PowerShell script for cleaning up the VixTemp folder on dental imaging workstations, which matches the core functionality.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Fix all issues with AI agents
In `@rmm-misc/VixWinTempFolderCleanup`:
- Line 11: The .NOTES version string and the $ScriptVersion variable are out of
sync (one is 1.1.0, the other 1.1.2); update either the .NOTES heading or the
$ScriptVersion constant so they match (preferably set the .NOTES to the value in
$ScriptVersion or vice versa) and ensure both the human-readable .NOTES block
and the $ScriptVersion symbol are synchronized wherever they appear (including
any duplicate occurrences).
- Line 586: The log line uses $spaceCheck.FreeMB but incorrectly labels it "GB
free"; update the Write-Log call so units match: either log
"$($spaceCheck.FreeMB) MB free" or compute GB by dividing FreeMB by 1024 (e.g.
[$spaceCheck.FreeMB / 1024]) and log that value with "GB free"; ensure you also
adjust the RequiredMB label consistently (variables: Write-Log,
$spaceCheck.FreeMB, $spaceCheck.RequiredMB).
- Around line 208-210: The Get-UnixTimestamp function uses culture-sensitive
parsing ([double]::Parse on Get-Date -UFormat %s) which can break on non-US
locales; replace its body to use .NET's culture-independent Unix timestamp APIs
(e.g., call [DateTimeOffset]::UtcNow.ToUnixTimeSeconds() or
ToUnixTimeMilliseconds()/1000 if subsecond precision is needed) and return that
integer, ensuring you update the Get-UnixTimestamp function to directly return
the result from DateTimeOffset instead of parsing a formatted string.
🧹 Nitpick comments (1)
rmm-misc/VixWinTempFolderCleanup (1)

264-275: Potential file handle leak if Close() throws.

The current pattern OpenRead().Close() doesn't guarantee disposal if Close() fails. Consider using a try/finally block with Dispose().

♻️ Proposed fix for safer resource handling
             try {
                 # Test if file is accessible
-                $null = [System.IO.File]::OpenRead($file.FullName).Close()
+                $stream = [System.IO.File]::OpenRead($file.FullName)
+                $stream.Dispose()
                 $filePaths += $file.FullName
                 $archivedFiles += $file
                 $originalSizeBytes += $file.Length
             }

Fixes issues identified in code review:

- Fix version mismatch: .NOTES and $ScriptVersion now both 1.1.3
- Fix locale-sensitive timestamp parsing: replaced [double]::Parse(Get-Date -UFormat %s)
  with [DateTimeOffset]::UtcNow.ToUnixTimeSeconds() to avoid failures in non-US locales
  that use comma decimal separators
- Fix unit label in disk space log: changed "GB free" to "MB free" to match variable name
- Fix potential resource leak: file accessibility check now uses proper try/finally
  with explicit Dispose() to prevent handle leaks if closure fails

Bumps version to 1.1.3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant