41

What is the proper way to clear the recycle bin for all users in Windows Server 2008 R2?

1

7 Answers 7

36

As far as I can tell, these is no "official" Microsoft supported way of doing this. There are two options. One involves deleting c:\$Recycle.Bin and the other is scripting cleanmgr.exe to run at each user logon.

The closest thing to "official" support for deleting c:\$Recycle.bin is from this MS KB, which references XP and Vista, but implies the expected behavior.


Immediate deletion

If you want this to happen immediately, it seems that you can just run rd /s c:\$Recycle.Bin and Windows should re-create the necessary folders the next time that they are needed. I just tested this quickly and it appears to work, but -obviously- proceed with caution.


Recurring logon-scriptable deletion

You can do this with the Disk Cleanup tool (cleanmgr.exe). Unfortunately, Microsoft decided to bundle this with the "Desktop Experience" set of features, meaning you'll have to install a bunch of other crap and reboot.

The alternative is to grab the following two files and move them to the specified locations per Technet:

C:\Windows\winsxs\amd64_microsoft-windows-cleanmgr_31bf3856ad364e35_6.1.7600.16385_none_c9392808773cd7da\cleanmgr.exe
C:\Windows\winsxs\amd64_microsoft-windows-cleanmgr.resources_31bf3856ad364e35_6.1.7600.16385_en-us_b9cb6194b257cc63\cleanmgr.exe.mui

Cleanmgr.exe should go in %systemroot%\System32.

Cleanmgr.exe.mui should go in %systemroot%\System32\en-US.

Running cleanmgr alone won't let you clear everyone's recycle bin, but you can use /sageset and /sagerun to make a logon script that runs for all users via GPO that will clear their recycle bin on the next logon, as described here. It's not the cleanest thing, but it will work. The linked article is for XP, but the syntax is unchanged as of Server 2008 R2.

4
  • Did a little research on it, there was this link that elaborates a little. social.technet.microsoft.com/Forums/en-US/winserverManagement/… Nov 14, 2011 at 14:50
  • Tested, this doesn't clear it for all users. Don't really want to have to contact our contractor and have him log in just to delete some files... Nov 14, 2011 at 14:58
  • Yeah, I can confirm this behavior as well. It seems that either scripting cleanmgr to run at each login is the closest thing to an official MS way of doing it. The alternative is to blow away the recycle bin folder on each profile. It should recreate it on the next login for each user, but I'd be a little weary to try this in production.
    – MDMarra
    Nov 14, 2011 at 15:08
  • More on automating CleanMgr here... stackoverflow.com/a/35214197/80161 Dec 2, 2016 at 16:24
9

I don't think there is a proper way documented as the recycle bins for users are kept separate in their profiles; this would also be a security hazard to allow because documents or items in the recycle bin, if perused by users, could allow certain documents to be leaked.

It might be possible to script an administrator-privileged script to run and clear files from the trash of each local profile (but that might still be synced to the server holding your profiles if you have roaming profiles). But you need to have permissions and ownership properly set; I know on our servers Administrator does not have proper access to profiles on the storage server; administrator has to take ownership of the profile, and when we're done return ownership to the proper user or else profiles don't work properly for them anymore.

You could try running a process at logoff that clears the trash directory per user, but that also entails accidentally deleting something that they want to recover later and will now be gone since it was deleted at last logoff.

Probably the "proper" way to do it is to configure quotas on workstations and servers and when that quota is hit for storage, the user learns they have to delete items from the recycle bin. Because of security it would be a training issue. Otherwise you'd need a workaround.

@markm had a utility suggestion that appears to do this; I stand by the assertion that it's not a "proper" way since it's an add-on and not built into Windows by default (although I'm not surprised that the helpful administration utility isn't included.) The only other problem I'd worry about in using it is that it might have to be run on a workstation and on the server or you might have profile syncing issues with what appears where. It looks like it's supposed to be just a mini-tool for accessing the "disk cleanup" tab in Windows.

Another thought...untested...would be to use folder redirection to redirect their trash folder to a central server. I would classify this as a monumentally Bad Idea(tm), however. Then you'd delete their files from that shared directory. Linking this over the network, security setup, etc. would make this a level one priority kludge that would make other sysadmins run away before spontaneously combusting, however.

5
  • 1
    Disk cleanup run as an elevated user doesn't hit everyone's recycle bin?
    – MDMarra
    Nov 14, 2011 at 14:42
  • I kinda hope not even if it does making tidying up a PITA. In a shared environment such as a terminal server that has potential for nastiness.
    – Rob Moir
    Nov 14, 2011 at 14:45
  • Hm, intersting. Looks like I need to test this.
    – MDMarra
    Nov 14, 2011 at 14:47
  • I deleted it when @MarkM's answer sounded the most canonically reasonable, but it sounds like it doesn't work for all users after KyleBrandt tested it. I'm thinking there isn't a documented way to do it properly due to security, most likely...the ability to delete other user's stuff since the trash is part of their (roaming) profile could be a security risk. Nov 14, 2011 at 15:03
  • Deleted my answer, that is. Nov 14, 2011 at 15:06
6

I ran TreeSize Free and saw I had 15gigs in the Recycle Bin, but I couldn't see it, probably because it was done by a long departed user. But in TreeSize Pro I could delete it, which put the data into the Recycle Bin that I could see.

1
  • 9
    WinDirStat could've done that for free. It's my go to tool when I need to figure out what is using all of the space on a hard drive. You can right-click on a file or folder and delete it to the recycle bin or permanently, you can also right-click and open an Explorer window there or a Command Prompt. It also has no qualms about showing you all of the users Recycle Bins, though you have to look up the SIDs and match them up to each user yourself.
    – JamesH
    Aug 27, 2014 at 17:42
3

This works for me:-

Get-ChildItem "C:\`$Recycle.bin\" | Remove-Item -Recurse -Force

It will remove the recycle.bin; Windows will re-create the recycle bin as required, i.e. as soon as a user deletes a new file.

Might no be the most elegant code and there may well be a better way to do it but it will help free up space on a congested server. You can test it using the -WhatIf switch on the Remove-Item command.

Get-ChildItem "C:\`$Recycle.bin\" | Remove-Item -Recurse -Force -WhatIf

NB: Each drive maintains its own recycle bin; so you'd want to replace the drive letter with whichever drive you're running this command for, or you can use the following for all local drives:

Get-PSProvider -PSProvider FileSystem `
| Select-Object -ExpandProperty Drives `
| Where-Object { $_.DisplayRoot -notlike "\\*" } `
| Select-Object -ExpandProperty Root `
| ForEach-Object { "$_`$Recycle.bin\" } `
| Where-Object { Test-Path -Path $_ -PathType Container } `
| ForEach-Object { Get-ChildItem -Path $_ -Force | Remove-Item -Recurse -Force }

Hope this helps

0
1

I had a recycle bin that was showing over 4GB of data but I was unable to clear it. Went in and found a bunch of profiles that were no longer used on the server and removed them under system properties - Advanced - User Profiles and now the recycle bin is empty.

Obviously don't delete any accounts that are still current or in use but as an administrator, you can do it this way.

0

I liked this solution because is easy to understand what it is doing and it does the job, but in order to work from any location you run the command from, you need to run change it like this (adding a \ after the "drive_letter:") and to be able to delete those folder from other users.. you need to add the "-force" at the end of the remove-item command. Additionally as you are deleting all folders within C:\$Recycle.bin\ you do not need to include "-recurse" when getting the child items. So this will be the final command i would use instead:

Get-ChildItem "C:`$Recycle.bin\" -Force | Remove-Item -Recurse -force -WhatIf

removing -WhatIf if you want to do more than only testing the command

0

Use below process to remove all files.

  1. login as admin user & explore c drive
  2. unchecked hide protected operating system file from folder options
  3. browse $Recycle.Bin folder
  4. delete all files & folders
  5. empty your recycle bin

All files will be deleted from disk.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .