Solved

Check Remote Folder Size from CMD line

Posted on 2006-10-31
17
8,360 Views
Last Modified: 2008-03-03
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
Comment
Question by:master_windu
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
17 Comments
 
LVL 43

Expert Comment

by:Steve Knight
ID: 17848247
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
 
LVL 43

Expert Comment

by:Steve Knight
ID: 17848261
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
 

Author Comment

by:master_windu
ID: 17849730

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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
LVL 43

Expert Comment

by:Steve Knight
ID: 17849876
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
 
LVL 43

Expert Comment

by:Steve Knight
ID: 17849896
This is batch file BTW.  It should be dirsize.cmd not VBS.

Steve
0
 

Author Comment

by:master_windu
ID: 17850972
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
 

Author Comment

by:master_windu
ID: 17851012
"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
 
LVL 43

Expert Comment

by:Steve Knight
ID: 17851417
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
 
LVL 43

Expert Comment

by:Steve Knight
ID: 17851645
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
 

Author Comment

by:master_windu
ID: 17853880
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
 
LVL 43

Expert Comment

by:Steve Knight
ID: 17854225
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
 
LVL 43

Expert Comment

by:Steve Knight
ID: 18290553
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
 
LVL 22

Expert Comment

by:WMIF
ID: 18447992
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
 
LVL 43

Expert Comment

by:Steve Knight
ID: 18451406
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
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 18715502
PAQed with points refunded (500)

Computer101
EE Admin
0

Featured Post

Free eBook: Backup on AWS

Everything you need to know about backup and disaster recovery with AWS, for FREE!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Changing MS Windows 2003 Server product key 6 328
Registry Error Stop 0X0000051 3 2,857
Windows startup/shutdown date/time log 7 155
AD account Auto logoff 1 39
NTFS file system has been developed by Microsoft that is widely used by Windows NT operating system and its advanced versions. It is the mostly used over FAT file system as it provides superior features like reliability, security, storage, efficienc…
While it may be true that the internet is a place of possibilities, it is also a hostile environment lurking with many dangers. By clicking on the wrong link, trusting the wrong person or using a weak password, you are virtually inviting hackers to …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question