Chelseawillrecover
Chelseawillrecover

Reputation: 2644

Get total size of Recycle Bin

I have a need and have not been able to find any question related to what I intend to achieve. I am trying to get a script (either PowerShell or DOS WMI) to get total size of recycle bin but where there are more than one drive.

I have tried using this command line DIR /S %SYSTEMDRIVE%\$RECYCLE.BIN | FINDSTR /C:File(s) but this only shows me size of recycle bin usage on the C: drive but I need to also get size for other drives on each servers irrespective of the drive letters used.

I have checked Script Guy but couldn't find any close to it.

Upvotes: 0

Views: 9035

Answers (1)

Robin
Robin

Reputation: 1645

I use the "Get-RecycleBinSize" script from http://gallery.technet.microsoft.com/scriptcenter/Get-RecycleBinSize-092f15c7

It's fantastic. I've tested it against 2003, 2008, 2008 R2 and 2012. It returns an object for each recycle bin (i.e. by drive, and user account). An example:

Get-RecycleBinSize -ComputerName server01

Computer : server01
Drive    : C:
User     : Domain\username
BinSID   : S-1-5-21-1231231234-1231231234-1231231234-12345
Size     : 20

The returned size is in KB so you might want to do some formatting on this.

Whilst using it for reporting purposes, I've also incorporated it into a script that emails users when their recycle bin is over a certain size to ask them to empty it. You can however can forcefully empty it with the -empty parameter.

To get the total space used by the server you could run the following:

Get-RecycleBinSize -ComputerName server01 | % { $totalspace = $totalspace + [System.Math]::Round($_.Size/1MB,0) }
$totalspace

Upvotes: 5

Related Questions