Powershell Script for Directory Size

I am looking for a script to list the size of all home directories.  Does anyone have a PowerShell Script for this?  Or can they guide me in the right direction.  Thanks.
jduran04Asked:
Who is Participating?
 
MlandaTCommented:
function Get-DirectorySize() {
  param ([string]$root = $(resolve-path .))
  gci -re $root |
    ?{ -not $_.PSIsContainer } |
    measure-object -sum -property Length
}

usage: $sum = (Get-DirectorySize "Some\File\Path").Sum
0
 
ReneGeCommented:
Here is my batch file version.

Cheers,
Rene

 
@ECHO OFF

SETLOCAL enabledelayedexpansion

IF EXIST %~n0.txt DEL %~n0.txt

FOR /F "delims=" %%A IN ('DIR /b /a:d') DO (
	FOR /F "tokens=1-4 delims= " %%B IN ('DIR /S "%%A"') DO (
		ECHO %%C | FINDSTR -i "File(s)" >NUL && SET FolderSize=%%D %%E
	)
	ECHO [%%A] [!FolderSize!]
)

ECHO.
PAUSE
EXIT

Open in new window

0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
ReneGeCommented:
Disregard line 5
0
 
ReneGeCommented:
With defining the home folder

 
@ECHO OFF

SETLOCAL enabledelayedexpansion

SET HomeFolder=C:\BatchFiles

PUSHD "%HomeFolder%"
FOR /F "delims=" %%A IN ('DIR /b /a:d') DO (
	FOR /F "tokens=1-4 delims= " %%B IN ('DIR /S "%%A"') DO (
		ECHO %%C | FINDSTR -i "File(s)" >NUL && SET FolderSize=%%D %%E
	)
	ECHO [%%A] [!FolderSize!]
)
POPD

ECHO.
PAUSE
EXIT

Open in new window

0
 
jduran04Author Commented:
Thanks.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.