cleanup recycle bin cleaner
This commit is contained in:
@@ -64,15 +64,11 @@ 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"
|
||||
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}"
|
||||
}
|
||||
Try { Remove-Item -Path $item.FullName -Force -ErrorAction Continue }
|
||||
Catch { Write-Error $_.Exception.Message }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user