Created
February 13, 2026 03:25
-
-
Save lirrensi/1f10a02fe5adc89c9996d1155210d24e to your computer and use it in GitHub Desktop.
Smol pwsh script that keeps your external enclosure HDDs spinning forever without sleep. Useful for loud drives and reduces mechanical wear if your controller is very agressive and puts to sleep every 5min or so. It pokes ALL drives, ssd are safe anyway, but all HDDs will wake!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Drive Keep-Alive Script - WAKEY WAKEY ALL THE DRIVES | |
| # Pokes every drive letter every X minutes so they dont fucking sleep! | |
| Write-Host "🔄 Starting Drive Keep-Alive Monitor..." -ForegroundColor Cyan | |
| Write-Host "Press Ctrl+C to stop`n" -ForegroundColor Yellow | |
| function Get-AllDrives { | |
| # Get all drive letters that are ready (mounted and accessible) | |
| $drives = Get-PSDrive -PSProvider FileSystem | Where-Object { | |
| $_.Used -ne $null -and $_.Free -ne $null | |
| } | Select-Object -ExpandProperty Name | |
| return $drives | |
| } | |
| function Poke-Drive { | |
| param([string]$DriveLetter) | |
| try { | |
| $path = "${DriveLetter}:\" | |
| # Try direct drive access first (works for external drives) | |
| try { | |
| $handle = [System.IO.File]::Open( | |
| "\\.\${DriveLetter}:", | |
| [System.IO.FileMode]::Open, | |
| [System.IO.FileAccess]::Read, | |
| [System.IO.FileShare]::ReadWrite | |
| ) | |
| $buffer = New-Object byte[] 512 | |
| $handle.Read($buffer, 0, 512) | Out-Null | |
| $handle.Close() | |
| } | |
| catch { | |
| # Fallback: Write a tiny file (forces real disk I/O) | |
| $tempPath = Join-Path $path ".__keepalive__.tmp" | |
| [System.IO.File]::WriteAllText($tempPath, (Get-Date).Ticks.ToString()) | |
| Remove-Item $tempPath -Force | |
| } | |
| $timestamp = Get-Date -Format "HH:mm:ss" | |
| Write-Host "[$timestamp] ✨ Poked ${DriveLetter}: - " -NoNewline -ForegroundColor Green | |
| Write-Host "WAKEY WAKEY!" -ForegroundColor Magenta | |
| return $true | |
| } | |
| catch { | |
| $timestamp = Get-Date -Format "HH:mm:ss" | |
| Write-Host "[$timestamp] ⚠️ Failed to poke ${DriveLetter}: - $($_.Exception.Message)" -ForegroundColor Red | |
| return $false | |
| } | |
| } | |
| # Main loop | |
| $intervalSeconds = 180 | |
| Write-Host "🔍 Detecting all drives...`n" -ForegroundColor Cyan | |
| while ($true) { | |
| $allDrives = Get-AllDrives | |
| if ($allDrives.Count -eq 0) { | |
| Write-Host "⚠️ No drives detected! This shouldn't happen..." -ForegroundColor Yellow | |
| } | |
| else { | |
| Write-Host "💾 Found drives: $($allDrives -join ', ')" -ForegroundColor Cyan | |
| foreach ($drive in $allDrives) { | |
| Poke-Drive -DriveLetter $drive | |
| Start-Sleep -Milliseconds 300 # Brief pause between drives | |
| } | |
| } | |
| Write-Host "`n💤 Sleeping for some time...`n" -ForegroundColor DarkGray | |
| Start-Sleep -Seconds $intervalSeconds | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment