Using du.exe (Sysinternals) is it possible to show folders above a certain size?

As the other answer says, you can't do it with du.exe alone. PowerShell to the rescue!

.\du.exe -c -l 3 C:\ | ConvertFrom-Csv -Header Size,Path | Where-Object { [int]$_.Size -gt 1048576 } | Sort-Object { [int]$_.Size } -descending

Explanation

Breaking that long command down into the individual bits that are each piped into the next one:

.\du.exe -c -l 3 C:\

This is basically what you started with, except the -c parameter tells du to format the output as CSV.

ConvertFrom-Csv -Header Size,Path

This takes the CSV output from du and converts it into a PowerShell hashtable. Since du doesn't provide a header with column names, that has to be done manually.

Where-Object { [int]$_.Size -gt 1048576 }

This filters the data, returning only those rows where the size is greater than 1 GB (du returns sizes in KB, and 1 GB = 1048576 KB). Note the [int] part, to let PowerShell know that it's dealing with numeric data.

Sort-Object { [int]$_.Size } -descending

This sorts the data by size, in descending order (again specifying that the data to sort by is numeric). This is optional, of course.


In the latest du.exe version appending a header with Powershell ConvertFrom-Csv doesn't work out of the box, because du.exe appends it's own header in the listing. What we need to do is select the existing header with select command.

du.exe -c -l 3 C:\ | ConvertFrom-Csv | select Path,DirectorySize | Where-Object { [int]$_.DirectorySize -gt 1048576 }

I'm providing a new variant on the previous du / powershell combos, just because neither of them worked for me with du v1.61, and others may face the same issue. I ran into a few problems with the previous variants:

  1. du's -nobanner switch needs to be included (and wasn't) so that ConvertFrom-Csv doesn't choke on the banner at the top (for me, manifesting as mysterious invisible output)
  2. Even then, powershell would return e.g. Cannot convert value "40822284152" to type "System.Int32". Error: "Value was either too large or too small for an Int32." for some lines; presumably very large directories.
  3. Lastly, the output would include very small directories, well below 1GB, despite the presence of Where-Object { [int]$_.DirectorySize -gt 1048576 }

I'm not a powershell expert, but I've managed to adapt the previous two variants to provide a working solution:

du -nobanner -c -l 3 \ | ConvertFrom-Csv | select Path,@{Name="DirectorySize";expression={$_.DirectorySize / 1GB }} | Where-Object { $_.DirectorySize -gt 1 } | Sort-Object { $_.DirectorySize } -descending

And just for giggles, here's a less flexible / less precise solution using du and findstr with a regular expression:

du -l 3 \ | findstr /R /C:",[0-9][0-9][0-9],[0-9][0-9][0-9]  "

This takes advantage of the pattern that directories over 1GB will be printed in. Specifically there will be an extra leading comma before the three digits, and then another comma followed by three more digits. The trailing two spaces are required to filter out the totals that are printed at the bottom. Note: this solution doesn't sort by directory size as with the powershell solution.