Skip to content

Instantly share code, notes, and snippets.

@HamousOnWheels
Created April 3, 2018 13:59
Show Gist options
  • Select an option

  • Save HamousOnWheels/2cfdd2ef5ba1939a2bbf6480b8d1b251 to your computer and use it in GitHub Desktop.

Select an option

Save HamousOnWheels/2cfdd2ef5ba1939a2bbf6480b8d1b251 to your computer and use it in GitHub Desktop.
Clear recycle bin items older than 6 months
$Shell = New-Object -ComObject Shell.Application
$Global:Recycler = $Shell.NameSpace(0xa)
foreach($item in $Recycler.Items())
{
$DeletedDate = $Recycler.GetDetailsOf($item,2) -replace "\u200f|\u200e",""
$dtDeletedDate = get-date $DeletedDate
If($dtDeletedDate -lt (Get-Date).AddMonths(-6))
{
Remove-Item -Path $item.Path -Confirm:$false -Force -Recurse
}#EndIF
}#EndForeach item
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment