PowerShell Recycling bin size Get-ChildItem issues
Im a bit lost. Been working on a script to check the size of the C and if less then 20 Gig, notify me and get usual suspect folder sizes. Been using Get-ChildItem for Deskp, Docs, Music, etc. but having issues with the bin.
When I run,
Get-ChildItem C:\ -Hidden -force
Get-ChildItem C results w/ -hidden
but $Recycle.Bin and several other seem to not show file size. Had seen several long codes that people have made on gethub but there must be a sorter way.
Also when I run,
Get-ChildItem C:\$RECYCLE.BIN
PS can't find the path. I take it the $ makes it a variable and don't want to change each user's bin name as a work around.
Solution 1:
the following will get the sum of the .Length
properties of the files in the recycle bin ...
(Get-ChildItem -LiteralPath 'C:\$Recycle.Bin' -File -Force -Recurse -ErrorAction SilentlyContinue |
Measure-Object -Property Length -Sum).Sum
output [in bytes, on my system, today] = 249852365
what it does ...
- grabs the files from the recycle bin
the single quotes around the path name prevent PoSh from trying to expand the$Recycle
. [grin] - the
Measure-Object
grabs all the.Length
properties & sums them - the final
.Sum
grabs just that value from the output ofM-O