fix cleaners for recycle bin and autodesk installers

This commit is contained in:
2025-08-15 15:48:16 -04:00
parent 1036cca39a
commit c3a89f73bb
+17 -14
View File
@@ -59,21 +59,24 @@ If ( $OldTempFiles ) {
}
# Remove all old files from the Recycle Bin
$RecycleBin = (New-Object -ComObject Shell.Application).NameSpace(0xa)
ForEach($file in $RecycleBin.Items()) {
# Remove RTL and LTR marks from date string so it can be compared
$DateDeleted = $Recycler.GetDetailsOf($item,2) -replace "\u200f|\u200e",""
# Make sure the item has expired
If( (Get-Date $DateDeleted) -lt ((Get-Date) - $TimeDelta)) {
# Delete the item
$path = $file.Path
Write-Output "Deleting expired Recycle Bin item: ""${path}"""
Try { Remove-Item -Path $path -Force -Recurse }
$UserRecycleBins = Get-ChildItem -Path "${Env:SystemDrive}\`$Recycle.Bin" -Directory -ErrorAction SilentlyContinue
If ( ($UserRecycleBins | Measure-Object).Count -gt 0 ) {
Write-Output "Deleting all recycle bin items older than ${OlderThan} days from:"
ForEach ( $userRecycleBin in $UserRecycleBins ) {
$userRecycleBinFullName = $userRecycleBin.FullName
Write-Output " - $userRecycleBinFullName"
$items = Get-ChildItem -Path $userRecycleBin.FullName -Recurse -ErrorAction SilentlyContinue
ForEach ( $item in $items ) {
If ( $item.LastWriteTime -lt $TimeDelta ) {
Try {
Remove-Item -Path $item.FullName -Force -ErrorAction Continue
$itemFullName = $item.FullName
Write-Output "DELETING: ${itemFullName}"
}
Catch { Write-Error $_.Exception.Message }
}
}
}
}
# Turn off system hibernation if it's in use
@@ -124,7 +127,7 @@ If ( Test-Path $ESDB ) {
# Remove any Autodesk installers at their default location
$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") }
$foldersToDelete = Get-ChildItem -Path $ADSKInst -ErrorAction SilentlyContinue | Where-Object { ($_.PSIsContainer) -and ($_.LastWriteTime -lt ((Get-Date) - $TimeDelta)) -and ( $_.Name -ne "WI") }
ForEach ( $f in $foldersToDelete ) {
$path = $f.FullName
Write-Output "Deleting Autodesk installer directory: ""${path}"""