[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 8394
  • Last Modified:

Check Remote Folder Size from CMD line

Hello

I simply want to check the folder size of a particular directory on a remote server i.e \\server1\dept

I am not concerned about the number of files or their size, just the size of the folder

I am looking for a way to do this from the cmd line since i need to check the sizes of 2 directories on about 70 servers

I have looked at the dir cmd switches but couldn't get it to show me the size of the directory

There are various utilities that can show me this info from within windows but it takes far too long.

I also looked at the DIRUSE reskit utility but it also took too long to return results.

Can someone help me out here

Thanks
0
master_windu
Asked:
master_windu
1 Solution
 
Steve KnightIT ConsultancyCommented:
Well apart from DIRUSE and TreeSize you could use a plain DIR command as follows.  It is always going to be slow as effectively it will run down all files in the dir no matter how you do it.

@echo off
set dirpath=\share\path\*.*
for /f "tokens=3" %%b in ('dir  /-c/s ^| find "File(s)"') do set total=%%b

You could run this against a server list with a batch file like this - ask if not sure on any of it.

@echo off
if not exist serverlist.txt echo servlist.txt not found & pause & goto end

for /f "tokens=*" %%a in (serverlist.txt) do call :process %%a

goto end
:process

for /f "tokens=3" %%b in ('dir  \\%1\%dirpath% /-c/s ^| find "File(s)"') do set total=%%b

:end

Steve
0
 
Steve KnightIT ConsultancyCommented:
Sorry you would probably want to add a line such as

echo %1, %dirpath%, %total%
echo %1, %dirpath%, %total% >> dirsize.txt

 before the :end line to write the output to a file and screen
0
 
master_winduAuthor Commented:

Thanks Dragon-it

Im not a big scripting person

I copied onto a text file and saved as dirsize.vbs

So if you could, can you show me how to modify the script you gave to give me the directory size for the following example:

\\server3\e$\dept
\\server3\e$\users

Also where do I need to save serverlist.txt?

thanks



0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
Steve KnightIT ConsultancyCommented:
Ah OK.  Tell you what then lets change it to put the server and path in the file:

serverlist.txt contains
server,path  
e.g.
server3,e$\dept

You can put servlist.txt wherever you like as long as you change the path.  I've made it easier by setting the path for it at the top of the file.  Same goes for the file with the results in.

hth

Steve

@echo off
set servlist=c:\serverlist.txt
if not exist %servlist% echo %servlist% not found & pause & goto end

set listfile=c:\dirsize.txt
del %listfile% 2>NUL

REM run down each entry in serverlist file and pickup servername and directory path and pass them to process sub
for /f "tokens=1,2*" %%a in (%servlist%) do call :process %%a %%b

goto end

REM for each path run a dir command run it through find to get the totals and pick up the last line into Total and echo it to a file
:process

for /f "tokens=3" %%x in ('dir  \\%1\%2 /-c/s ^| find "File(s)"') do set total=%%x

echo %1, %2, %total%
echo %1, %2, %total% >> %listfile%

:end
 
0
 
Steve KnightIT ConsultancyCommented:
This is batch file BTW.  It should be dirsize.cmd not VBS.

Steve
0
 
master_winduAuthor Commented:
Thanks

I tested it out on a local server and it worked.  However it would have been nice if there was an option to return the file size in MB

But when I ran it against a remote server it took way longer.  After about 5 mins i canceled it as no data had yet been returned.  If it takes that long to return folder sizes from remote servers then it wouldn't be a viable option for me since I need to check about 70 servers.  In the test the remote dirs each had about 5 gb of data

I looked at treesize but the free version does support network.  The pro version does but again it takes quite a long time to return results for just 1 remote dir

When I do a DIR \\serverX\e$\users I get a quick return but without the info I need.  Im looking for something more or less this fast that I can make a batch file out of to get me returns on all the servers.

0
 
master_winduAuthor Commented:
"But when I ran it against a remote server it took way longer.  After about 5 mins i canceled it as no data had yet been returned."

there were only 2 remote directories in the serverlist.txt file   fyi
0
 
Steve KnightIT ConsultancyCommented:
I don't believe you will get anything fast though if you run it locally on the server it will be faster of course.  Any such program has to add up sizes of all files in the dirs.

if you left it going then a second run would probably be faster as the server caches the dir entries.

Even if you just use explorer and look at the properties of the dir you will notice it takes ages.

The command won't print anything until it has finished that dir.

Steve
0
 
Steve KnightIT ConsultancyCommented:
btw type dir \\server\path /s/-c to see what it is doing.  It then pulls out the files(s) total lines using find.

Sorry it is no good but without some sort of indexer on the server it will always be a slow process.  Free space on the other hand is easy enough!

Could you not just set it to run last thing at night and leave it to give you a result the next morning :-)
0
 
master_winduAuthor Commented:
thanks for all your effort dragon-it

what i ended up doing was copying diruse.exe to the c$ dir of every file server via a batch file

then i created another batch file with psexec so that diruse runs locally on each server.

example

psexec \\server3 \\server3\c$\diruse /m \\server3\dept
psexec \\server3 \\server3\c$\diruse /m \\server3\users

this seems to work

ill output it to a text file
0
 
Steve KnightIT ConsultancyCommented:
fair enough.  You'd decided against diruse which is why I went down the route asked for but running it on the remote server with psexec or rclient /runbatch etc. is a much quicker idea if the option is avaialble to you.

If you write the output to a shared folder , I.e.>>\\server\share\servername.txt then it is easy enough to amalgamate into one with a copy command for instance. Or write it to same path on each server and pickup the logs afterwards with a for loop

Good luck

Steve
0
 
Steve KnightIT ConsultancyCommented:
I feel it more appropriate to select an answer I gave...I offered solutions and suggested the only way to make it run faster was to run it locally on the server - I did not elaborate on that as it had to be run remotely.
0
 
WMIFCommented:
it seems to me that master_windu has come up with a solution to his problem which has not used your suggestions.  though you may have a more appropriate suggestion, this is not what master_windu used.  how can i recommend one of your answers in this case?

WMIF
EE Cleanup Volunteer
0
 
Steve KnightIT ConsultancyCommented:
OK, if he had said it could be run on the server I would have used the same scripts run on each box and amalgamted but lets just close the Q, not that bothered about it!
0
 
Computer101Commented:
PAQed with points refunded (500)

Computer101
EE Admin
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now