Link to home
Create AccountLog in
Avatar of jduran04
jduran04Flag for United States of America

asked on

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.
ASKER CERTIFIED SOLUTION
Avatar of Mlanda T
Mlanda T
Flag of South Africa image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
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

Disregard line 5
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

Avatar of jduran04

ASKER

Thanks.