Dear Team,

I need a script to get each user’s (c:/users/username/desktop/recycle.bin) recycle bin folder size.

These users are local users on the same server.

I can go to each folder and get the details via properties ( c:/user/username/desktop/recycle.bin) but this is time-consuming.

So please help me with a script. the output result should only require username and recycle.bin size.

7 Spice ups

What do you have in your script so far?

I don’t have one, I need a new script.

With respect, people here are not going to write it for you. We will guide you.

1 Spice up

Thanks, Please note I am not in PowerShell.

Because I am curious, why do you need the size of users recycle bin?

Is this a one-off or something you need frequently?

Yes brother, We need to monitor disc usage by user level.

But you want a script specifically for the recycle bin. Why not set user quotas.

Sorry for the delayed reply,

I can’t set the user quota because it will affect total user profile. as i know there is no separate quota limit for recycle bin.

We are running a terminal (rdp) server and have some users on this. So sometimes users delete some files and do even not empty the recycle bin.

So if we know who is crossing the limit we can monitor and remove them.

Why not just empty the bin periodically?

How I will empty the bin periodically?As an admin, I can see each user’s recycle bin size via c:/users/username/desktop/recycle.bin properties. But if I open the recycle bin folder it will redirect to the admin recycle bin.
Recently I have tried All recycle bins empty CMD with Drive level (C:/D:E: etc.) But this does not empty all boxes.
Then another method is via user log-off script but this will also take time while logging off . Because most of the users will log off at the same time (end shift) can cause extreme load on the server read/write.
Here I am planning to have a simple script that will show each user’s Recycle bin usage. So that I can at least monitor easily.

Hope you understand.

A couple of ways

1 Spice up

If you’re running out of Disk Space (“The Final Frontier”), the last place you should look is the Recycle Bin. Windows counts that space as “Available” as needed.

Perhaps all you need to do is limit the Recycle Bin’s size: How to change Recycle Bin storage settings on Windows 10 | Windows Central ? Or (same article) just bypass its use altogether?

You probably already know what the Clear-RecycleBin cmdlet will do… Clear-RecycleBin (Microsoft.PowerShell.Management) - PowerShell | Microsoft Learn

Lastly, perhaps this blog can open some doors:

Hi!

Check this script, is in powershell and you can easily use PowerShell ISE to run it:

$recycleBinPath = 'C:\$Recycle.Bin'

# Agafar la paperes
$sidFolders = Get-ChildItem -Path $recycleBinPath -Directory -Force
$results = @()

foreach ($sidFolder in $sidFolders) {
    # sid de la carpeta
    $sid = $sidFolder.Name

    # Get user name
    try {
        $user = (New-Object System.Security.Principal.SecurityIdentifier($sid)).Translate([System.Security.Principal.NTAccount]).Value
    } catch {
        $user = "Unknown user($sid)"
    }

    # Get folder size
    $size = Get-ChildItem -Path $sidFolder.FullName -Recurse -Force -ErrorAction SilentlyContinue | Measure-Object -Property Length -Sum

    if ($size.Sum -gt 0) {
        # tamany bin:
        $results += [PSCustomObject]@{
            'User'     = $user
            'Size (MB)' = [Math]::Round($size.Sum / 1MB, 2)
        }
    }
}

# Show res:
if ($results.Count -gt 0) {
    $results | Sort-Object 'Size (MB)' -Descending | Format-Table -AutoSize
} else {
    Write-Host "No results"
}
1 Spice up

Your first post - so welcome, but a little strange you post a script but no description of what it does or why.

For anyone wondering, this script identifies the users who have items in the Recycle Bin and calculates the total size of those items. It then displays the results in a table, sorted by the size of the Recycle Bin contents for each user.