delete the correct shadow copies

This commit is contained in:
2024-10-14 12:57:41 -04:00
parent 63792a557f
commit cec26755f9
+5 -5
View File
@@ -120,13 +120,13 @@ If ( Test-Path $ADSKInst ) {
# Delete all but most recent shadow copy of system drive
$SystemVolume = Get-CimInstance -ClassName Win32_Volume -ErrorAction SilentlyContinue | Where-Object { $_.Name -like "${Env:SystemDrive}\" }
$ShadowCopies = Get-CimInstance -ClassName Win32_ShadowCopy | Where-Object { $_.VolumeName -like $SystemVolume.DeviceID }
If ( $ShadowCopies.Length -gt 1 ) {
Write-Output "Deleting all of the oldest shadow copies on ${Env:SystemDrive}"
$ShadowsToDelete = $ShadowCopies.Length - 1
If ( $ShadowCopies.Count -gt 1 ) {
Write-Output "Deleting all of the oldest shadow copies of ${Env:SystemDrive}"
$ShadowsToDelete = $ShadowCopies.Count - 1
While ( $ShadowsToDelete -gt 0 ) {
$ShadowsToDelete = $ShadowsToDelete - 1
vssadmin delete shadows /For=$Env:SystemDrive /Oldest /Quiet
}
$ShadowsToDelete = $ShadowsToDelete - 1
}
}
# Delete old temp directories from Chocolatey cache