Skip to content
-
Subscribe to our newsletter & never miss our best posts. Subscribe Now!
The Server Admin
The Server Admin
  • Home
  • Linux
  • Windows
  • About
  • What Powers The Server Admin
  • Home
  • Linux
  • Windows
  • About
  • What Powers The Server Admin
Close

Search

  • https://www.facebook.com/
  • https://twitter.com/
  • https://t.me/
  • https://www.instagram.com/
  • https://youtube.com/
Subscribe
Windows

du -h -s but for Windows

By Anthony
March 23, 2024 3 Min Read
0

As you know the du command in Linux is amazingly powerful, it is a quick and easy way to dig into a directory and get content size and more. Well personally one of the biggest things I have with Windows is from the PowerShell you can’t really do this….. Easily.

Lets take a look at a few things first, I want a directory listing in Linux I just simply run the ls -lah and this will show the output of the contents in said folder,

Great so I can do that in Windows, its called the dir command.

Ok, but how big is that folder? How much stuff is inside of it? Example how big is the Downloads Folder? Well hmm, a dir does spit out some information, but I still have to math, which makes my brain hurt.

Ok so cool, but I can do that in Linux no problems. Linux allows us two, well many different options, the biggest two that I use, and I will use the above example, is the du -h -s /home/torresoc/ and the du -h -s /home/torresoc/* And look at the difference.

Now this allows you to start digging down into the folders and in this example, the user torresoc we can note that the mail folder is where all the data is being held at. This is great for helping to find who is hording all the storage.

Now in Windows ** Again we are working from the command line/powershell not a gui where you can just right click on something, and then wait, and right click and wait, and so forth.

Ok so you made your point, now how do I do the same thing in powershell?

This took me some time to find and hack together, but it works, now the big part it has to be on the different lines when you past it into the prompt. Currently it is not a one line command.

gci -force “C:\Users”-ErrorAction SilentlyContinue | ? { $_ -is [io.directoryinfo] } | % {
$len = 0
gci -recurse -force $_.fullname -ErrorAction SilentlyContinue | % { $len += $_.length }
$_.fullname, ‘{0:N2} GB’ -f ($len / 1Gb)
}

So the above is a great way to show you the users and their disk usage.

Great! In this example ** Please note that this would be more used in a server environment and I am using my desktop as the example, so the Users folder is well empty but me. You can see that the user atorr is using 17.01 GB of disk space. Great! Now we can go dig even further into this and find even more.

Lets change from C:\Users to C:\Users\atorr

Cool so now we can see tha this user has 4.33 GB of data in the Downloads folder. Ok so if this was in an office environment we could dig even deeper into this users folder and see whats what. This is a great script that I have learned and use almost every single day now that I am working back in the Windows server world.

*** UPDATE ***

So I figured out how to do this on one line so we now don’t have to worry about the line breaks.

gci -force "C:\Users\hw" -ErrorAction SilentlyContinue | ? { $_ -is [io.directoryinfo] } | % { $len = 0; gci -recurse -force $_.fullname -ErrorAction SilentlyContinue | % { $len += $_.length }; $_.fullname, '{0:N2} GB' -f ($len / 1Gb) }

Now copy that and paste it, and it will spit out the same results, but now not worrying about the line breaks!

Author

Anthony

Follow Me
Other Articles
Previous

How can I clone a Windows 10/11 disk onto a larger disk?

Next

BackupScript with RoboCopy

No Comment! Be the first one.

Leave a Reply

You must be logged in to post a comment.

Search

Need a Virtual Server for sysctl testing? Check out our plans!

Popular Posts

  • Mount sFTP folder as local drive
    by Anthony
    June 9, 2026
  • Robocopy Examples
    by Anthony
    February 12, 2026
  • Rsync Command Examples
    by Anthony
    February 10, 2026

Trending

  • Mount sFTP folder as local drive
    by Anthony
    June 9, 2026
  • Adding a GUI to a Server or VPS
    by Anthony
    August 27, 2024
  • Back up to a shared folder with Time Machine on Mac
    by Anthony
    January 4, 2025
  • Backup Your Databases
    by Anthony
    March 24, 2024

Editors Picks

    Send an email:
    mail@example.com

    Call me:
    123-456-7890

    • Facebook
    • Twitter
    • Instagram
    • TikTok
    • LinkedIn
    • Behance
    Copyright 2026 — The Server Admin. All rights reserved. Blogsy WordPress Theme