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
|
# Remove all old files from the Recycle Bin
|
||||||
$RecycleBin = (New-Object -ComObject Shell.Application).NameSpace(0xa)
|
$UserRecycleBins = Get-ChildItem -Path "${Env:SystemDrive}\`$Recycle.Bin" -Directory -ErrorAction SilentlyContinue
|
||||||
ForEach($file in $RecycleBin.Items()) {
|
If ( ($UserRecycleBins | Measure-Object).Count -gt 0 ) {
|
||||||
|
Write-Output "Deleting all recycle bin items older than ${OlderThan} days from:"
|
||||||
# Remove RTL and LTR marks from date string so it can be compared
|
ForEach ( $userRecycleBin in $UserRecycleBins ) {
|
||||||
$DateDeleted = $Recycler.GetDetailsOf($item,2) -replace "\u200f|\u200e",""
|
$userRecycleBinFullName = $userRecycleBin.FullName
|
||||||
|
Write-Output " - $userRecycleBinFullName"
|
||||||
# Make sure the item has expired
|
$items = Get-ChildItem -Path $userRecycleBin.FullName -Recurse -ErrorAction SilentlyContinue
|
||||||
If( (Get-Date $DateDeleted) -lt ((Get-Date) - $TimeDelta)) {
|
ForEach ( $item in $items ) {
|
||||||
|
If ( $item.LastWriteTime -lt $TimeDelta ) {
|
||||||
# Delete the item
|
Try {
|
||||||
$path = $file.Path
|
Remove-Item -Path $item.FullName -Force -ErrorAction Continue
|
||||||
Write-Output "Deleting expired Recycle Bin item: ""${path}"""
|
$itemFullName = $item.FullName
|
||||||
Try { Remove-Item -Path $path -Force -Recurse }
|
Write-Output "DELETING: ${itemFullName}"
|
||||||
Catch { Write-Error $_.Exception.Message }
|
}
|
||||||
|
Catch { Write-Error $_.Exception.Message }
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -124,7 +127,7 @@ If ( Test-Path $ESDB ) {
|
|||||||
# Remove any Autodesk installers at their default location
|
# Remove any Autodesk installers at their default location
|
||||||
$ADSKInst = "${Env:SystemDrive}\Autodesk"
|
$ADSKInst = "${Env:SystemDrive}\Autodesk"
|
||||||
If ( Test-Path $ADSKInst ) {
|
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 ) {
|
ForEach ( $f in $foldersToDelete ) {
|
||||||
$path = $f.FullName
|
$path = $f.FullName
|
||||||
Write-Output "Deleting Autodesk installer directory: ""${path}"""
|
Write-Output "Deleting Autodesk installer directory: ""${path}"""
|
||||||
|
|||||||
Reference in New Issue
Block a user