Windows Server Core is designed for minimalism stripped down to reduce attack surface, maintenance overhead, and update footprint. However, its very nature excludes many GUI-based utilities that seasoned admins might rely on for day-to-day maintenance. One such tool is the classic Disk Cleanup utility (cleanmgr.exe), which is notably absent in Server Core environments.
In production, the consequences of neglecting system housekeeping can accumulate quickly cluttered log directories, stale update caches, orphaned user profiles, and bloated temp folders all contribute to disk pressure and potential service degradation. These issues are especially critical on VMs with fixed-size VHDs or on systems operating under strict compliance or backup windows.
To address this gap with precision and control, the EguibarIT.HousekeepingPS PowerShell module provides a comprehensive suite of cleanup functions tailored for headless, GUI-less, automated environments. At its heart is the Start-DiskCleanup wrapper, which orchestrates a series of specialized cleanup routines to reclaim disk space, reduce clutter, and keep your servers running at optimal performance.
The module provides the following functions related to “Disk Cleanup Activities”:
- Start-DiskCleanup
- Clear-CCMcache
- Clear-DeliveryOptimizationFile
- Clear-ErrorReport
- Clear-LogFile
- Clear-RecycleBin
- Clear-TemporaryFile
- Clear-TemporaryFolder
- Clear-UserProfile
- Clear-WindowsLog
- Clear-WindowsServerCoreCleanup
- Clear-WindowsUpdate
Let s walk through some realistic use cases where this module becomes indispensable.
Real-World Scenarios for Automated Housekeeping
Monthly VM Image Maintenance
You re preparing a golden image for Windows Server 2022 Core to be sysprepped and distributed across your infrastructure. Before sealing the image, you want to ensure it’s as lean as possible no stale updates, no user profile remnants, and no leftover setup files. By executing Start-DiskCleanup -IncludeAll -Verbose in your image finalization script, you invoke full cleanup functionality to sanitize the build without relying on GUI-based utilities.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
PS C:\> Import-Module EguibarIT.HousekeepingPS PS C:\> Start-DiskCleanup -? NAME Start-DiskCleanup SYNOPSIS Comprehensive system cleanup utility. SYNTAX Start-DiskCleanup [[-IncludeAll]] [-WhatIf] [-Confirm] [<CommonParameters>] Start-DiskCleanup [[-DisableHibernation]] [[-RecycleBin]] [[-Folders]] [[-Image]] [[-SystemRestorePoints]] [[-Profiles]] [[-WindowsUpdate]] [[-CCM]] [[-ErrorReport]] [[-WindowsLogs]] [[-TempFiles]] [[-DeliveryOptimization]] [[-LogFiles]] [-WhatIf] [-Confirm] [<CommonParameters>] DESCRIPTION Wrapper function to perform various system cleanup operations including: - Hibernation file removal - Recycle bin cleanup - Temporary folders cleanup - Windows image cleanup - System restore points - User profiles - Windows update cache - CCM cache - Error reports - Windows logs - Delivery optimization files - Log files Requires administrative privileges. RELATED LINKS https://github.com/vreguibar/EguibarIT.HousekeepingPS REMARKS To see the examples, type: "get-help Start-DiskCleanup -examples". For more information, type: "get-help Start-DiskCleanup -detailed". For technical information, type: "get-help Start-DiskCleanup -full". For online help, type: "get-help Start-DiskCleanup -online" PS C:\> Start-DiskCleanup -IncludeAll -Confirm:$false WARNING: The names of some imported commands from the module 'DeliveryOptimization' include unapproved verbs that might make them less discoverable. To find the commands with unapproved verbs, run the Import-Module command again with the Verbose parameter. For a list of approved verbs, type Get-Verb. WARNING: No active Delivery Optimization download or upload jobs WARNING: No active Delivery Optimization download or upload jobs Success SpaceRecovered OperationsRun Errors ------- -------------- ------------- ------ True 14370972 13 {} PS C:\> |
SCCM Cache Oversaturation
One of your branch office servers doubles as a local distribution point and has been swallowing up disk space due to misconfigured package deployments. A quick scheduled task running Clear-CCMcache can prune unnecessary cached content while gracefully interacting with the Configuration Manager client API, preserving system stability.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
PS C:\> Clear-CCMcache -? NAME Clear-CCMcache SYNOPSIS Cleans the Configuration Manager (CCM) client cache. SYNTAX Clear-CCMcache [-Force] [-WhatIf] [-Confirm] [<CommonParameters>] DESCRIPTION This function removes cached content from the Configuration Manager (SCCM/CCM) client cache. It uses the UIResource.UIResourceMgr COM object to properly clean the cache through the CCM API. If the CCM client is not present, it checks for orphaned cache folders. The function requires administrative privileges to access the CCM client. RELATED LINKS https://github.com/vreguibar/EguibarIT.HousekeepingPS https://docs.microsoft.com/en-us/mem/configmgr/core/clients/manage/manage-clients REMARKS To see the examples, type: "get-help Clear-CCMcache -examples". For more information, type: "get-help Clear-CCMcache -detailed". For technical information, type: "get-help Clear-CCMcache -full". For online help, type: "get-help Clear-CCMcache -online" PS C:\> Clear-CCMcache -Force -Verbose VERBOSE: ═══════════════════════════════════════════════════════════════════════════ EguibarIT.HousekeepingPS module ═══════════════════════════════════════════════════════════════════════════ Date: 09/07/2025 Starting: Clear-CCMcache Parameters used by the function... Name Value ---- ----- Force True Verbose True VERBOSE: Perform operation 'Enumerate CimInstances' with following parameters, ''namespaceName' = root\ccm,'className' = SMS_Client'. VERBOSE: CCM client not found or WMI namespace unavailable Success : True CacheSize : 0 ItemsCleared : 0 Message : CCM client not installed or WMI namespace unavailable Errors : {} VERBOSE: Function Clear-CCMcache finished clearing CCM Cache." ─────────────────────────────────────────────────────────────────────────── Success : True CacheSize : 0 ItemsCleared : 0 Message : CCM client not installed or WMI namespace unavailable Errors : {} |
Patch Tuesday Aftermath
After the monthly patch rollout, you’re left with 2GB of residual update files and Delivery Optimization artifacts. These aren t critical anymore but still take up precious space. The combination of Clear-DeliveryOptimizationFile and Clear-WindowsUpdate allows you to surgically clean up without affecting future update behavior. This is particularly helpful on Server Core VMs with limited OS partitions.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
PS C:\> Clear-DeliveryOptimizationFile -? NAME Clear-DeliveryOptimizationFile SYNOPSIS Delete Delivery Optimization files. SYNTAX Clear-DeliveryOptimizationFile [-WhatIf] [-Confirm] [<CommonParameters>] DESCRIPTION This function finds and deletes Delivery Optimization files from the cache. It requires administrative privileges and provides detailed progress information. Falls back to using Disk Cleanup if PowerShell method fails. RELATED LINKS https://github.com/vreguibar/EguibarIT.HousekeepingPS REMARKS To see the examples, type: "get-help Clear-DeliveryOptimizationFile -examples". For more information, type: "get-help Clear-DeliveryOptimizationFile -detailed". For technical information, type: "get-help Clear-DeliveryOptimizationFile -full". For online help, type: "get-help Clear-DeliveryOptimizationFile -online" PS C:\> Clear-DeliveryOptimizationFile -Verbose VERBOSE: ═══════════════════════════════════════════════════════════════════════════ EguibarIT.HousekeepingPS module ═══════════════════════════════════════════════════════════════════════════ Date: 09/07/2025 Starting: Clear-DeliveryOptimizationFile Parameters used by the function... Name Value ---- ----- Verbose True VERBOSE: Loading module from path 'C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\DeliveryOptimization\Microsoft.Windows.DeliveryOptimization.AdminCommands.dll'. VERBOSE: Loading module from path 'C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\DeliveryOptimization\DeliveryOptimizationVerboseLogs.psm1'. VERBOSE: Loading module from path 'C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\DeliveryOptimization\DeliveryOptimizationSettings.psm1'. VERBOSE: Loading module from path 'C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\DeliveryOptimization\DeliveryOptimizationStatus.psm1'. VERBOSE: Importing cmdlet 'Get-DeliveryOptimizationLog'. VERBOSE: Importing cmdlet 'Get-DeliveryOptimizationLogAnalysis'. WARNING: The names of some imported commands from the module 'DeliveryOptimization' include unapproved verbs that might make them less discoverable. To find the commands with unapproved verbs, run the Import-Module command again with the Verbose parameter. For a list of approved verbs, type Get-Verb. VERBOSE: The 'Delete-DeliveryOptimizationCache' command in the DeliveryOptimization' module was imported, but because its name does not include an approved verb, it might be difficult to find. The suggested alternative verbs are "Remove". VERBOSE: Importing function 'Delete-DeliveryOptimizationCache'. VERBOSE: Importing function 'Disable-DeliveryOptimizationVerboseLogs'. VERBOSE: Importing function 'Enable-DeliveryOptimizationVerboseLogs'. VERBOSE: Importing function 'Get-DeliveryOptimizationPerfSnap'. VERBOSE: Importing function 'Get-DeliveryOptimizationPerfSnapThisMonth'. VERBOSE: Importing function 'Get-DeliveryOptimizationStatus'. VERBOSE: Importing function 'Get-DOConfig'. VERBOSE: Importing function 'Get-DODownloadMode'. VERBOSE: Importing function 'Get-DOPercentageMaxBackgroundBandwidth'. VERBOSE: Importing function 'Get-DOPercentageMaxForegroundBandwidth'. VERBOSE: Importing function 'Set-DeliveryOptimizationStatus'. VERBOSE: Importing function 'Set-DODownloadMode'. VERBOSE: Importing function 'Set-DOMaxBackgroundBandwidth'. VERBOSE: Importing function 'Set-DOMaxForegroundBandwidth'. VERBOSE: Importing function 'Set-DOPercentageMaxBackgroundBandwidth'. VERBOSE: Importing function 'Set-DOPercentageMaxForegroundBandwidth'. WARNING: No active Delivery Optimization download or upload jobs VERBOSE: Using native PowerShell fallback method VERBOSE: Performing the operation "Manual cleanup" on target "Delivery Optimization Cache". VERBOSE: Processing cache location: C:\WINDOWS\ServiceProfiles\NetworkService\AppData\Local\Microsoft\Windows\DeliveryOptimization\Cache VERBOSE: No Delivery Optimization cache files found to clean WARNING: No active Delivery Optimization download or upload jobs VERBOSE: Function Clear-DeliveryOptimizationFile finished removing Delivery Optimization cache." ─────────────────────────────────────────────────────────────────────────── Success BytesFreed Method Errors ------- ---------- ------ ------ True 0 NativePowerShell {} PS C:\> Clear-WindowsUpdate -? NAME Clear-WindowsUpdate SYNOPSIS Delete Windows Update cache files safely. SYNTAX Clear-WindowsUpdate [-WhatIf] [-Confirm] [<CommonParameters>] DESCRIPTION This function safely removes Windows Update cache files by properly stopping and starting the Windows Update service. It requires administrative privileges and provides detailed progress information. RELATED LINKS https://github.com/vreguibar/EguibarIT.HousekeepingPS REMARKS To see the examples, type: "get-help Clear-WindowsUpdate -examples". For more information, type: "get-help Clear-WindowsUpdate -detailed". For technical information, type: "get-help Clear-WindowsUpdate -full". For online help, type: "get-help Clear-WindowsUpdate -online" Clear-WindowsUpdate -Verbose VERBOSE: ═══════════════════════════════════════════════════════════════════════════ EguibarIT.HousekeepingPS module ═══════════════════════════════════════════════════════════════════════════ Date: 09/07/2025 Starting: Clear-WindowsUpdate Parameters used by the function... Name Value ---- ----- Verbose True VERBOSE: Getting initial cache size... Confirm Are you sure you want to perform this action? Performing the operation "Remove Cache" on target "C:\WINDOWS\SoftwareDistribution". [Y] Yes [A] Yes to All [N] No [L] No to All [?] Help (default is "Y"): a VERBOSE: Function Clear-WindowsUpdate finished removing Windows Update cache." ─────────────────────────────────────────────────────────────────────────── Success BytesFreed ServiceState Errors ------- ---------- ------------ ------ True 7888898 Running {} |
Log File Accumulation
Your file server’s log directory has grown to several GB due to verbose diagnostics enabled during a recent incident. A customized job using Clear-LogFile -Directory ‘C:\Windows\debug’ -Days 45 ensures that only stale logs are removed, preserving recent data for analysis while freeing disk space.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
PS C:\> Clear-LogFile -? NAME Clear-LogFile SYNOPSIS Find and delete log files older than specified days. SYNTAX Clear-LogFile [[-Directory] <String>] [[-Days] <Int32>] [-WhatIf] [-Confirm] [<CommonParameters>] DESCRIPTION This function searches for and deletes log files within a specified directory that are older than a given number of days. It supports filtering by file age and provides detailed progress information. RELATED LINKS https://github.com/vreguibar/EguibarIT.HousekeepingPS REMARKS To see the examples, type: "get-help Clear-LogFile -examples". For more information, type: "get-help Clear-LogFile -detailed". For technical information, type: "get-help Clear-LogFile -full". For online help, type: "get-help Clear-LogFile -online" PS C:\> Clear-LogFile -Directory 'C:\Windows\debug' -Days 45 -Verbose VERBOSE: ═══════════════════════════════════════════════════════════════════════════ EguibarIT.HousekeepingPS module ═══════════════════════════════════════════════════════════════════════════ Date: 09/07/2025 Starting: Clear-LogFile Parameters used by the function... Name Value ---- ----- Directory C:\Windows\debug Days 45 Verbose True VERBOSE: Found 4 files in C:\Windows\debug VERBOSE: Function Clear-LogFile finished removing Log files." ─────────────────────────────────────────────────────────────────────────── Success FilesRemoved BytesFreed Errors ------- ------------ ---------- ------ True 0 0 {} |
Proactive Profile Management
On Remote Desktop Session Hosts (RDSH), it’s common for disconnected or expired user profiles to remain indefinitely. Using Clear-UserProfile -ProfileAge 30 helps automate profile hygiene by removing dormant, unmounted profiles preventing quota violations and performance hits.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
PS C:\> Clear-UserProfile -? NAME Clear-UserProfile SYNOPSIS Delete unused user profiles from the system. SYNTAX Clear-UserProfile [[-ProfileAge] <Int32>] [-WhatIf] [-Confirm] [<CommonParameters>] DESCRIPTION This function finds and deletes user profiles that haven't been used for a specified number of days. It excludes system profiles and currently loaded profiles. Requires administrative privileges. RELATED LINKS https://github.com/vreguibar/EguibarIT.HousekeepingPS REMARKS To see the examples, type: "get-help Clear-UserProfile -examples". For more information, type: "get-help Clear-UserProfile -detailed". For technical information, type: "get-help Clear-UserProfile -full". For online help, type: "get-help Clear-UserProfile -online" PS C:\> Clear-UserProfile -ProfileAge 30 -Verbose VERBOSE: ═══════════════════════════════════════════════════════════════════════════ EguibarIT.HousekeepingPS module ═══════════════════════════════════════════════════════════════════════════ Date: 09/07/2025 Starting: Clear-UserProfile Parameters used by the function... Name Value ---- ----- ProfileAge 30 Verbose True VERBOSE: Retrieving user profiles... VERBOSE: Perform operation 'Enumerate CimInstances' with following parameters, ''namespaceName' = root\cimv2,'className' = Win32_UserProfile'. VERBOSE: Operation 'Enumerate CimInstances' complete. VERBOSE: Found 0 eligible profiles VERBOSE: Function Clear-UserProfile finished clear user profiles." ─────────────────────────────────────────────────────────────────────────── Success ProfilesRemoved BytesFreed Errors ------- --------------- ---------- ------ True 0 0 {} |
Error Reporting and Dump Cleanup
After a blue screen or application crash, dump files and WER folders quietly occupy significant storage. Clear-ErrorReport methodically scrubs these areas clean, allowing for post-mortem analysis before triggering cleanup manually or as part of a routine maintenance cycle.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
PS C:\> Clear-ErrorReport -? NAME Clear-ErrorReport SYNOPSIS Find and delete error report files and dump files. SYNTAX Clear-ErrorReport [-WhatIf] [-Confirm] [<CommonParameters>] DESCRIPTION This function searches for and removes Windows error reports and memory dump files from the system drive and Windows Error Reporting (WER) folders. It handles both standard dump files (*.dmp) and Windows Error Reporting data. Requires administrative privileges to access system folders. RELATED LINKS https://github.com/vreguibar/EguibarIT.HousekeepingPS REMARKS To see the examples, type: "get-help Clear-ErrorReport -examples". For more information, type: "get-help Clear-ErrorReport -detailed". For technical information, type: "get-help Clear-ErrorReport -full". For online help, type: "get-help Clear-ErrorReport -online" PS C:\> Clear-ErrorReport -Verbose VERBOSE: ═══════════════════════════════════════════════════════════════════════════ EguibarIT.HousekeepingPS module ═══════════════════════════════════════════════════════════════════════════ Date: 09/07/2025 Starting: Clear-ErrorReport Parameters used by the function... Name Value ---- ----- Verbose True VERBOSE: Processing System dump files VERBOSE: Processing Windows Error Reporting files VERBOSE: Function Clear-ErrorReport finished removing Error reports." ─────────────────────────────────────────────────────────────────────────── Success FilesRemoved BytesFreed Errors ------- ------------ ---------- ------ True 0 0 {} |
PowerShell with Purpose
The true power of the EguibarIT.HousekeepingPS module lies in its modularity and automation-readiness. Each function can be executed independently or invoked through the Start-DiskCleanup orchestrator, enabling full control in scheduled tasks, DSC configurations, or CI/CD pipelines for image preparation.
In contrast to traditional GUI-driven cleanup tools, these PowerShell functions offer:
- Granular targeting (e.g., age filters, specific locations)
- Administrative precision using COM objects and trusted APIs
- Safe execution with built-in service handling (e.g., Windows Update, TrustedInstaller)
- Verbose logging for auditability and troubleshooting
For modern IT environments that demand automation, compliance, and agility, having this housekeeping toolkit in your PowerShell arsenal is not just helpful it s essential.
You can explore and contribute to the project at EguibarIT.HousekeepingPS on GitHub