As enterprise workstations, developer laptops, and virtual desktops handle large system updates, container images, and offline cloud synchronizations, available disk capacity on system drives (typically SSDs) can rapidly degrade. Windows 11 features Storage Sense, an automated background maintenance engine that autonomously purges temporary system files, empties the Recycle Bin on defined schedules, and dehydrates unused OneDrive or cloud-synced files. Systems administrators can configure, enforce, and audit Storage Sense policies across Windows 11 endpoints using PowerShell.
Understanding Storage Sense Architecture and Cleanup Triggers
Storage Sense operates as a scheduled maintenance task managed by the Windows Storage service. Its primary cleanup routines target four distinct areas:
- Temporary Files Cleanup: Scans
C:\Windows\Tempand user-level%TEMP%folders to purge cached setup files, error reports, and temporary installer payloads not currently locked by running applications. - Recycle Bin Cadence: Automatically purges items from the Recycle Bin that have resided there longer than a designated period (e.g. 14, 30, or 60 days).
- Downloads Folder Retention: Optionally deletes files stored in the user’s Downloads folder if they have remained unmodified for a specified number of days.
- Cloud File Dehydration (OneDrive Files On-Demand): Automatically switches locally pinned cloud files to online-only status if they have not been accessed within a defined threshold, reclaiming local flash storage without deleting data from the cloud.
Auditing Current Storage Sense Configuration via PowerShell
Storage Sense policies are stored within the Windows Registry under the user and machine policy paths. Inspect current configuration settings using PowerShell:
# Query user-level Storage Sense registry configuration
$senseKey = "HKCU:\Software\Microsoft\Windows\CurrentVersion\StorageSense\Parameters\StoragePolicy"
if (Test-Path $senseKey) {
Get-ItemProperty -Path $senseKey | Select-Object * -ExcludeProperty PS*
} else {
Write-Host "Storage Sense is currently using system defaults (unconfigured)."
}
Enabling Storage Sense and Configuring Cleanup Cadence via PowerShell
To programmatically enable Storage Sense and establish an aggressive automated maintenance schedule, configure the following registry values:
$sensePath = "HKCU:\Software\Microsoft\Windows\CurrentVersion\StorageSense\Parameters\StoragePolicy"
if (!(Test-Path $sensePath)) {
New-Item -Path $sensePath -Force | Out-Null
}
# 1. Enable Storage Sense (1 = Enabled, 0 = Disabled)
Set-ItemProperty -Path $sensePath -Name "01" -Value 1 -Type DWord
# 2. Set Execution Cadence (2048 = Every week, 1024 = Every day, 4096 = During low free disk space)
Set-ItemProperty -Path $sensePath -Name "2048" -Value 2048 -Type DWord
# 3. Clean Temporary Files automatically (1 = Enabled)
Set-ItemProperty -Path $sensePath -Name "04" -Value 1 -Type DWord
# 4. Recycle Bin retention in days (e.g. 30 days)
Set-ItemProperty -Path $sensePath -Name "08" -Value 30 -Type DWord
# 5. Downloads folder retention (0 = Never, 30 = 30 days)
Set-ItemProperty -Path $sensePath -Name "32" -Value 0 -Type DWord
Write-Host "Storage Sense successfully configured for weekly automated cleanups." -ForegroundColor Green
Enforcing Storage Sense via System-Wide Machine Policies (Intune / GPO)
To enforce Storage Sense across all users on a managed workstation or remote enterprise device, apply settings to the Local Machine policy hive:
$gpoPath = "HKLM:\SOFTWARE\Policies\Microsoft\Windows\StorageSense"
if (!(Test-Path $gpoPath)) {
New-Item -Path $gpoPath -Force | Out-Null
}
# Enforce Storage Sense globally
Set-ItemProperty -Path $gpoPath -Name "AllowStorageSenseGlobal" -Value 1 -Type DWord
# Set cleanup frequency: 1 = Daily, 2 = Weekly, 3 = Monthly, 4 = Low Disk Space
Set-ItemProperty -Path $gpoPath -Name "ConfigStorageSenseGlobalCadence" -Value 2 -Type DWord
# Set Recycle Bin cleanup age threshold (30 days)
Set-ItemProperty -Path $gpoPath -Name "StorageSenseRecycleBinCleanupThreshold" -Value 30 -Type DWord
# Dehydrate OneDrive files older than 30 days
Set-ItemProperty -Path $gpoPath -Name "StorageSenseCloudContentDehydrationThreshold" -Value 30 -Type DWord
Triggering an On-Demand Storage Sense Execution via CLI
To immediately execute a full cleanup cycle without waiting for the scheduled background timer:
# Trigger silent background cleanup pass via Windows CleanMgr
cleanmgr /autoclean
# Alternatively, trigger the Storage Sense maintenance task
Get-ScheduledTask -TaskName "StorageSense" -ErrorAction SilentlyContinue | Start-ScheduledTask
Automating Storage Sense policies via PowerShell prevents low-disk storage warnings, reduces system image bloat, and maintains optimal operating system drive performance across Windows 11 deployments.