delete the correct shadow copies

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