Skip to content

Add VixTemp folder cleanup script for dental imaging workstations#40

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

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

Conversation

@AlrightLad

@AlrightLad AlrightLad commented Jan 30, 2026

Copy link
Copy Markdown

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

coderabbitai Bot commented Jan 30, 2026

Copy link
Copy Markdown
Contributor

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

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
             }

Comment thread rmm-misc/VixWinTempFolderCleanup Outdated
Comment thread rmm-misc/VixWinTempFolderCleanup
Comment thread rmm-misc/VixWinTempFolderCleanup Outdated
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

@Gumbees Gumbees left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Summary

Adds a 653-line VixTemp folder cleanup script for dental imaging workstations (Vixwin/Dentimax/Curve). Archives oldest files when C:\vixtemp exceeds 250MB, maintains 5 rotating archives, server-detection guard, lock-file concurrency control, Ninja RMM alerting via Event Log, dual logging.

What works

  • Genuinely defensive design: workstation-only guard (Test-IsServer checking ProductType), lock-file with stale-lock detection (5min TTL), disk-space pre-check with 150% safety buffer, gracefully skips locked files.
  • Compress-Archive with rotation (vixtemp_archive_<unix>_<friendly>.zip, keep last 5) gives recovery without unbounded growth.
  • Overdue-cleanup alerting (24h since last success) catches the silent-failure mode where the script runs but exits early every time.
  • Explicit exit codes (0/1/2/3/4) are RMM-friendly.
  • Atomic operations: archive first, then delete only what was successfully archived ... never deletes files it couldn't archive.
  • DISABLE_CLEANUP override file is a nice operator escape hatch.
  • Follows the template properly. RMM variable block at top, $RMM dual-mode, Start-Transcript, $Description, $LogPath with fallback. This is the template-compliance gold standard for the current PR backlog.
  • File correctly placed in rmm-misc/ with .ps1 extension. Filename VixWinTempFolderCleanup ... actually wait, the diff shows rmm-misc/VixWinTempFolderCleanup with no .ps1 extension. See blockers.

Concerns

BLOCKER: Filename has no .ps1 extension. The diff adds rmm-misc/VixWinTempFolderCleanup ... no extension. PowerShell will not execute this as a script. Rename to rmm-misc/vixwin-temp-folder-cleanup.ps1 or similar.

Filename casing. PascalCase VixWinTempFolderCleanup should be kebab-case per PR #51.

Folder placement. This is a Vixwin/Dentimax/Curve specific cleanup. app-vixwin/ (which PR #35 creates) or app-dentrix/ would be more discoverable than rmm-misc/. Cross-coordinate with PR #35 which creates app-vixwin/VixTempCleanup.ps1 ... these two PRs are doing similar things in different folders.

Overlaps with PR #35. PR #35 adds app-vixwin/VixTempCleanup.ps1. This PR adds rmm-misc/VixWinTempFolderCleanup. Same author, same problem space, different folder, different filename. Pick one ... two scripts maintained in parallel is the worst outcome.

Suggestions

  • The 150% disk-space buffer is conservative ... probably fine but document why 1.5x specifically (vs 1.2x or 2x). Magic number deserves a comment.
  • Consider exposing $ThresholdMB and $TargetMB as RMM variables for per-site tuning ... 250MB is the documented Vixwin sensor failure threshold but some sites may want lower headroom.

Verdict

REQUEST CHANGES ... .ps1 extension blocker, and the overlap with PR #35 needs reconciliation before either lands. The script body itself is among the most defensively-coded in the backlog ... once the file is renamed and the duplicate is resolved, easy approve.

@Gumbees Gumbees changed the base branch from main to development May 11, 2026 17:09
@Gumbees Gumbees changed the base branch from development to main June 25, 2026 11:44
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.

2 participants