remove more than 1 shadow

This commit is contained in:
2023-11-09 13:34:09 -05:00
parent 2c35b31599
commit d37faa57dc
+6 -2
View File
@@ -117,12 +117,16 @@ If ( Test-Path $ADSKInst ) {
}
}
# Delete the oldest shadow copies if there are more than 1
# 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 oldest shadow copy on ${Env:SystemDrive}"
Write-Output "Deleting all of the oldest shadow copies on ${Env:SystemDrive}"
$ShadowsToDelete = $ShadowCopies.Length - 1
While ( $ShadowsToDelete -gt 0 ) {
$ShadowsToDelete = $ShadowsToDelete - 1
vssadmin delete shadows /For=$Env:SystemDrive /Oldest /Quiet
}
}
# Remove files from user profile directories