remove oldest shadow copy

This commit is contained in:
2023-11-09 12:20:20 -05:00
parent 0aa95ef948
commit ea6406e38f
+7 -4
View File
@@ -109,15 +109,18 @@ If ( Test-Path $ESDB ) {
$ADSKInst = "${Env:SystemDrive}\Autodesk"
If ( Test-Path $ADSKInst ) {
$foldersToDelete = Get-ChildItem -Path $ADKSInst -ErrorAction SilentlyContinue | Where-Object { ($_.PSIsContainer) -and ($_.LastWriteTime -lt ((Get-Date) - $TimeDelta)) -and ( $_.Name -ne "WI") }
ForEach ( $folder in $foldersToDelete ) {
$path = $folder.FullName
ForEach ( $f in $foldersToDelete ) {
$path = $f.FullName
Write-Output "Deleting Autodesk installer directory: ""${path}"""
Try { Remove-Item $folder -Force -Recurse -ErrorAction SilentlyContinue }
Try { Remove-Item $f -Force -Recurse -ErrorAction SilentlyContinue }
Catch { Write-Error $_.Exception.Message }
}
}
# TODO: Evaluate system restore points and delete them if they take up too much space
# Delete the oldest shadow copies if there are more than 1
$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 ) { vssadmin delete shadows /For=$Env:SystemDrive /Oldest /Quiet }
# Remove files from user profile directories
ForEach ( $userProfile in $(Get-UserProfiles) ) {