This is too long to tweet, even written as a one liner. But this will search a folder for top level subfolders and return the file usage for each.
Manage and Report Active Directory, Exchange and Microsoft 365 with
ManageEngine ADManager Plus - Download Free Trial
Exclusive offer on ADManager Plus for US and UK regions. Claim now!
ManageEngine ADManager Plus - Download Free Trial
Exclusive offer on ADManager Plus for US and UK regions. Claim now!
[cc lang="PowerShell"]
$folder="S:\"
dir $folder | where {$_.psIscontainer} | foreach {
$stat= dir $_.fullname -recurse | Measure-Object -property length -Sum
New-Object PSObject -property @{Folder=$_.FullName;Files=$stat.count;Size=$stat.Sum;}}
[/cc]
Again, this would be handy to turn into a function or scriptblock. This is far from perfect. For example, it doesn't like empty folders. But this should be a good starting point for your own script or function.
Awesome. Thank you.
I don’t like empty folders either, so that’s ok 🙂
Thank you very much I have been looking for something like this for the past 2 days. I just didn’t know the correct verbage to use while I was searching google. As I am still really new to powershell I was wondering is there a way to export this to a CSV file?
I am shooting in the dark here would it be something similar to:
$stat | export-csv -path test.csv
Thanks for the one liner
Rudy
That is exactly how you would do it.
Cool thank you very much! Would it be easy to change it to display in MB instead of KB?
Of course. Just change the division
SizeMB=$stats.sum/1MB