Get folder size with its locations

New Contributor

My disk gets full several times and i have to clean it manually. so , is there is any script which can tell me which folder is consuming more than 10gb with its location.

 

 

i tried this one - 

 

Get-ChildItem -path "C:\junk" -Directory -force -Recurse | sort -descending -property length |
Select-Object FullName |
ForEach-Object -Process{New-Object -TypeName PSObject -Property @{Name =$_.FullName;Size = (Get-ChildItem -path $_.FullName -Recurse -file -Force -ErrorAction SilentlyContinue |
Measure-Object -Property Length -Sum ).Sum/1kb}} |
Select-Object Name, @{Name="Size(MB)";Expression={("{0:N2}" -f($_.Size/1024))}}|
Out-GridView
6 Replies

Get-ChildItem -path "C:\junk" -Directory -force -Recurse | sort -descending -property length |
Select-Object FullName |
ForEach-Object -Process{New-Object -TypeName PSObject -Property @{Name =$_.FullName;Size = (Get-ChildItem -path $_.FullName -Recurse -file -Force -ErrorAction SilentlyContinue |
Measure-Object -Property Length -Sum ).Sum/1kb}} |
Select-Object Name, @{Name="Size(MB)";Expression={("{0:N2}" -f($_.Size/1024))}} | Where-Object 'Size(MB)' -GT 9.99 |
Out-GridView

Where-Object 'Size(MB)' -GT 9.99 was the thing that I added at the end.

Did this work for you?

@Harm_Veenstra No, I don't work. There is some issue while this script was trying to save the output in gridview. Although I also try to save the output in a file but still output doesn't get saved.

@ankit_bhat 

 

I checked it again and it does work now, it didn't work because of the -Folder which should have been -File

 

 

Get-ChildItem -path "C:\junk" -File -force -Recurse | sort -descending -property length |
Select-Object FullName |
ForEach-Object -Process{New-Object -TypeName PSObject -Property @{Name =$_.FullName;Size = (Get-ChildItem -path $_.FullName -Recurse -file -Force -ErrorAction SilentlyContinue |
Measure-Object -Property Length -Sum ).Sum/1kb}} |
Select-Object Name, @{Name="Size(MB)";Expression={("{0:N2}" -f($_.Size/1024))}} | Where-Object 'Size(MB)' -GT 9.99 |
Out-GridView

 

 

"Get-ChildItem -path "C:\junk" -Directory -force -Recurse | sort -descending -property length" All directories will have 0 length. 
 
I think you meant to use "Get-ChildItem -path "C:\junk" -File -force -Recurse | sort -descending -property length" 

@ankit_bhat 

Did the change to -File instead of -Folder work for you?