Hello All,
I’m trying to prepare powershell script which removes files from recycle bin. This script should check if files were removed 30 days ago or are in recycle bin longer and then remove them.
I found such script but I think that it is not correct as there are $_.LastWriteTime not somethink like DalateADate.
ForEach ($Drive in Get-PSDrive -PSProvider FileSystem) {
$Path = $Drive.Name + ':\$RECYCLE.BIN'
Get-ChildItem $Path -Force -Recurse -ErrorAction SilentlyContinue |
Where-Object { $_.LastWriteTime -lt (Get-Date).AddDays(-7) } |
Remove-Item -Recurse -Force
}
I’m completly new with powershell scripting and I spent a lot of hours to find out solutions but with no luck.
May I kindly ask you to give me some adive?
OS:Windows Server 2016
Regards,
Sebastian