Skip to content

Commit

Permalink
fix(CLEANUP): logic for drive detection
Browse files Browse the repository at this point in the history
  • Loading branch information
he3als committed Oct 9, 2024
1 parent 9d16855 commit 58192c4
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/playbook/Executables/CLEANUP.ps1
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.\AtlasModules\initPowerShell.ps1
function Invoke-AtlasDiskCleanup {
# Kill running cleanmgr instances, as they will prevent new cleanmgr from starting
Get-Process -Name cleanmgr -ErrorAction SilentlyContinue | Stop-Process -Force -ErrorAction SilentlyContinue
Get-Process -Name cleanmgr -EA 0 | Stop-Process -Force -EA 0
# Disk Cleanup preset
# 2 = enabled
# 0 = disabled
Expand Down Expand Up @@ -47,14 +47,21 @@ function Invoke-AtlasDiskCleanup {

# Check for other installations of Windows
# If so, don't cleanup as it will also cleanup other drives, which will be slow, and we don't want to touch other data
$noCleanmgr = $false
$drives = (Get-PSDrive -PSProvider FileSystem).Root | Where-Object { $_ -notmatch $(Get-SystemDrive) }
foreach ($drive in $drives) {
if (!(Test-Path -Path $(Join-Path -Path $drive -ChildPath 'Windows') -PathType Container)) {
Write-Output "No other Windows drives found, running Disk Cleanup."
Invoke-AtlasDiskCleanup
if (Test-Path -Path $(Join-Path -Path $drive -ChildPath 'Windows') -PathType Container) {
Write-Output "Not running Disk Cleanup, other Windows drives found."
$noCleanmgr = $true
break
}
}

if (!$noCleanmgr) {
Write-Output "No other Windows drives found, running Disk Cleanup."
Invoke-AtlasDiskCleanup
}

# Clear the user temp folder
foreach ($path in @($env:temp, $env:tmp, "$env:localappdata\Temp")) {
if (Test-Path $path -PathType Container) {
Expand Down

0 comments on commit 58192c4

Please sign in to comment.