In our Windows 7/Server 2008 R2 environment, we’ve noticed that users with roaming profiles and folder redirection have an interesting problem where the Recycle Bin is redirecting to the user profile folder (not to the home folder) AND reporting back rather strange file sizes. Unfortunately this is having an impact on the file server, with quite staggering amounts of space being chewed up.
There are a few aspect to this to be investigated ongoing, but the first problem to tackle was Recycle Bins which weren’t being emptied. I don’t like stuff in my Recycle Bin, but then I’m quite fastidious about such things – can’t expect everyone else to be the same, especially when it isn’t their computer or system.
So, the challenge is to force the Recycle Bin to be emptied. There isn’t a GPO to handle this (yet) but it can be achieved using PowerShell:
#Set Variables
$objShell = New-Object -ComObject Shell.Application
$objFolder = $objShell.Namespace(0xA)
#Empty Recycle Bin
$objFolder.items() | %{ remove-item $_.path -Recurse -Confirm:$false}Thanks to PowerShell cmdlet integration with Server 2008 R2 GPO, this little script can now be made to run at logoff against pre-defined groups. The script needs to be codesigned to do this, by a code signing cert signed by an authority which the domain workstations trust. Next, in the Group Policy Management snap-in create a new GPO and edit it, then go to User Configuration\Policies\Windows Settings\Scripts, right-click Logoff and select Properties. Select the “PowerShell Scripts” tab and then Add. By default it will browse to the domain Policies folder on SYSVOL – copy the .PS1 file into this location and then select it. Link the GPO to an appropriate OU and set the target scope. Now, when the affected users log off, the Recycle Bin will be automatically emptied.
Two things to note:
- If you want to target computers instead of users, create the policy in Computer Configuration, not User Configuration
- If you have a load of users who never log off, but simply hard power down the machines (like we do) also apply the policy at Logon as well as Logoff – that way you get them coming and going




Hi,
can you give me a powershell script for empty recycle bin for all users, please ?
I think that the windows 2008 $recycle.bin doesn’t work correct.
Thanks.
Gandalf
Many thanks for sharing this very useful code. Implemented this into an Windows XP script I am currently writing…thanks again!