fix cleaners for recycle bin and autodesk installers
This commit is contained in:
+18
-15
@@ -59,20 +59,23 @@ 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 }
|
||||
Catch { Write-Error $_.Exception.Message }
|
||||
$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 }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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}"""
|
||||
|
||||
Reference in New Issue
Block a user