→ 🚀What's New? Explore Lansweeper's Fall 2024 Updates! Fall Launch Blog !

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
techsupport1
Engaged Sweeper II
https://betanews.com/2020/06/06/free-up-disk-space-windows-10-may-2020-update/

How we can remotely/centrally initiate a disk cleanup/remove files for all system to reclaim the disk space for updated window 10 after updated version 2004?

Harddisk that most SSD/M2 are 256GB or 512GB in report, show completed / not yet perform.

1. Deployment Package.
2. Create Report - SQL Query
1 REPLY 1
CyberCitizen
Honored Sweeper
I have a deployment package with the following PowerShell script.

[CmdletBinding(SupportsShouldProcess=$true)]
Param()

##Run CleanUpMGR Automatically

Write-Verbose 'Beging script CleanUpMGRScript.ps1 target C:'
#Capture current free disk space on Drive C
$FreeSpaceBefore = (Get-WmiObject win32_logicaldisk -filter "DeviceID='C:'" | select Freespace).FreeSpace/1GB
$Computer = $env:COMPUTERNAME

$RegPath = 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches'
$RegName = 'StateFlags0100'
$RegValue = '3'
Write-Verbose 'Setting values for disk cleanup.'
New-ItemProperty -Path "$Regpath\Active Setup Temp Folders" -Name $RegName -Value $RegValue -PropertyType DWORD -Force -ErrorAction SilentlyContinue | Out-Null
New-ItemProperty -Path "$Regpath\Downloaded Program Files" -Name $RegName -Value $RegValue -PropertyType DWORD -Force -ErrorAction SilentlyContinue | Out-Null
New-ItemProperty -Path "$Regpath\Internet Cache Files" -Name $RegName -Value $RegValue -PropertyType DWORD -Force -ErrorAction SilentlyContinue | Out-Null
New-ItemProperty -Path "$Regpath\Memory Dump Files" -Name $RegName -Value $RegValue -PropertyType DWORD -Force -ErrorAction SilentlyContinue | Out-Null
New-ItemProperty -Path "$Regpath\Offline Page Files" -Name $RegName -Value $RegValue -PropertyType DWORD -Force -ErrorAction SilentlyContinue | Out-Null
New-ItemProperty -Path "$Regpath\Old ChkDsk Files" -Name $RegName -Value $RegValue -PropertyType DWORD -Force -ErrorAction SilentlyContinue | Out-Null
New-ItemProperty -Path "$Regpath\Previous Installations" -Name $RegName -Value $RegValue -PropertyType DWORD -Force -ErrorAction SilentlyContinue | Out-Null
New-ItemProperty -Path "$Regpath\Recycle Bin" -Name $RegName -Value $RegValue -PropertyType DWORD -Force -ErrorAction SilentlyContinue | Out-Null
New-ItemProperty -Path "$Regpath\Service Pack Cleanup" -Name $RegName -Value $RegValue -PropertyType DWORD -Force -ErrorAction SilentlyContinue | Out-Null
New-ItemProperty -Path "$Regpath\Setup Log Files" -Name $RegName -Value $RegValue -PropertyType DWORD -Force -ErrorAction SilentlyContinue | Out-Null
New-ItemProperty -Path "$Regpath\System Error Memory Dump Files" -Name $RegName -Value $RegValue -PropertyType DWORD -Force -ErrorAction SilentlyContinue | Out-Null
New-ItemProperty -Path "$Regpath\System Error Minidump Files" -Name $RegName -Value $RegValue -PropertyType DWORD -Force -ErrorAction SilentlyContinue | Out-Null
New-ItemProperty -Path "$Regpath\Temporary Files" -Name $RegName -Value $RegValue -PropertyType DWORD -Force -ErrorAction SilentlyContinue | Out-Null
New-ItemProperty -Path "$Regpath\Temporary Setup Files" -Name $RegName -Value $RegValue -PropertyType DWORD -Force -ErrorAction SilentlyContinue | Out-Null
New-ItemProperty -Path "$Regpath\Thumbnail Cache" -Name $RegName -Value $RegValue -PropertyType DWORD -Force -ErrorAction SilentlyContinue | Out-Null
New-ItemProperty -Path "$Regpath\Update Cleanup" -Name $RegName -Value $RegValue -PropertyType DWORD -Force -ErrorAction SilentlyContinue | Out-Null
New-ItemProperty -Path "$Regpath\Upgrade Discarded Files" -Name $RegName -Value $RegValue -PropertyType DWORD -Force -ErrorAction SilentlyContinue | Out-Null
New-ItemProperty -Path "$Regpath\Windows Defender" -Name $RegName -Value $RegValue -PropertyType DWORD -Force -ErrorAction SilentlyContinue | Out-Null
New-ItemProperty -Path "$Regpath\Windows Error Reporting Archive Files" -Name $RegName -Value $RegValue -PropertyType DWORD -Force -ErrorAction SilentlyContinue | Out-Null
New-ItemProperty -Path "$Regpath\Windows Error Reporting Queue Files" -Name $RegName -Value $RegValue -PropertyType DWORD -Force -ErrorAction SilentlyContinue | Out-Null
New-ItemProperty -Path "$Regpath\Windows Error Reporting System Archive Files" -Name $RegName -Value $RegValue -PropertyType DWORD -Force -ErrorAction SilentlyContinue | Out-Null
New-ItemProperty -Path "$Regpath\Windows Error Reporting System Queue Files" -Name $RegName -Value $RegValue -PropertyType DWORD -Force -ErrorAction SilentlyContinue | Out-Null
New-ItemProperty -Path "$Regpath\Windows ESD Installation Files" -Name $RegName -Value $RegValue -PropertyType DWORD -Force -ErrorAction SilentlyContinue | Out-Null
New-ItemProperty -Path "$Regpath\Windows Upgrade Log Files" -Name $RegName -Value $RegValue -PropertyType DWORD -Force -ErrorAction SilentlyContinue | Out-Null

Write-Verbose 'Starting CleanMgr.exe...'
Start-Process -FilePath CleanMgr.exe -ArgumentList '/sagerun:100' -WindowStyle Hidden -Wait

Write-Verbose 'Waiting for CleanMgr and DismHost processes. Second wait neccesary as CleanMgr.exe spins off separate processes.'
Get-Process -Name cleanmgr,dismhost -ErrorAction SilentlyContinue | Wait-Process

$UpdateCleanupSuccessful = $false
if (Test-Path $env:SystemRoot\Logs\CBS\DeepClean.log) {
$UpdateCleanupSuccessful = Select-String -Path $env:SystemRoot\Logs\CBS\DeepClean.log -Pattern 'Total size of superseded packages:' -Quiet
Write-Verbose "Update Cleanup Successful: $($UpdateCleanupSuccessful)"
}

$FreespaceAfter = (Get-WmiObject win32_logicaldisk -filter "DeviceID='C:'" | select Freespace).FreeSpace/1GB

Write-Verbose "$($Computer), $(Get-Date), Free Space Before: $($FreeSpaceBefore), Free Space After: $($FreeSpaceAfter), Reboot required: $($UpdateCleanupSuccessful)"
Write-Output "$($Computer), $(Get-Date), Free Space Before: $($FreeSpaceBefore), Free Space After: $($FreeSpaceAfter), Reboot required: $($UpdateCleanupSuccessful)" | Out-File "C:\Windows\Temp\DiskSpace.log" -Append

if ($UpdateCleanupSuccessful) {
Write-Verbose 'Rebooting to complete CleanMgr.exe Update Cleanup....'
#SHUTDOWN.EXE /r /f /t 0 /c 'Rebooting to complete CleanMgr.exe Update Cleanup....'
Exit 3010
}