Get cumulative Desktop folder size from profile share

  • Thread starter Thread starter David Trimboli
  • Start date Start date
D

David Trimboli

We've got a series of roaming profiles on \\server\profiles$ , and
they're asking me to get the total size of all Desktop folders (in
preparation for deploying Desktop Folder Redirection). I'm looking for a
quick way to determine this number. The script is proving trickier than
I'd thought. Any advice?
 
We've got a series of roaming profiles on \\server\profiles$ , and
they're asking me to get the total size of all Desktop folders (in
preparation for deploying Desktop Folder Redirection). I'm looking for a
quick way to determine this number. The script is proving trickier than
I'd thought. Any advice?

For the actual number, does this help?

for /f "tokens=3" %%a in ('dir^|find "File(s)"') do set size=%%a
 
We've got a series of roaming profiles on \\server\profiles$ , and they're
asking me to get the total size of all Desktop folders (in preparation for
deploying Desktop Folder Redirection). I'm looking for a quick way to
determine this number. The script is proving trickier than I'd thought.
Any advice?

Maybe something like this..

@echo off
setlocal
net use z: \\server\profiles$
for /f "tokens=*" %%a in ('dir /b /a:d z:') do (
for /f "tokens=3" %%b in ('dir /-C "z:\%%a\desktop"^|find "File(s)"') do
set /a size+=%%b
)

set /a size=%size%/1048576
echo Total size of desktop folders=%size% Megs

HTH

Matt
 
We've got a series of roaming profiles on \\server\profiles$ , and
they're asking me to get the total size of all Desktop folders (in
preparation for deploying Desktop Folder Redirection). I'm looking for a
quick way to determine this number. The script is proving trickier than
I'd thought. Any advice?

FOR /D %n IN (\\server\profiles$\*) DO du -b -s %n
where du.exe is from the AINTX tool set.

Dealing with spaces in usernames and capturing/parsing the output of
du.exe is left as an exercise for the reader.
 
foxidrive said:
For the actual number, does this help?

for /f "tokens=3" %%a in ('dir^|find "File(s)"') do set size=%%a

Yeah, I'd gotten that, but then getting it for each subdirectory,
parsing it, and adding them all together didn't seem to want to work for
me...
 
Matt Williamson said:
Maybe something like this..

@echo off
setlocal
net use z: \\server\profiles$
for /f "tokens=*" %%a in ('dir /b /a:d z:') do (
for /f "tokens=3" %%b in ('dir /-C "z:\%%a\desktop"^|find
"File(s)"') do set /a size+=%%b
)

set /a size=%size%/1048576
echo Total size of desktop folders=%size% Megs

Aha! I wasn't aware of the /C option for DIR! This is very much like
what I had been working on, but without messing with variable string
substitution.

It's not working straight away, but I'm sure I can fix it up, given that
/C option. Thanks, Matt!
 
David Trimboli said:
We've got a series of roaming profiles on \\server\profiles$ , and
they're asking me to get the total size of all Desktop folders (in
preparation for deploying Desktop Folder Redirection). I'm looking for
a quick way to determine this number. The script is proving trickier
than I'd thought. Any advice?

Thanks for everyone's help so far. I'm getting some strange behavior
with what I've got so far. Can anyone explain what's going on?

Some background: we have two profiles shares: \\server\profiles$ and
\\server\profile$. Each profile share is populated with roaming
profiles: directories of eight characters or less, with no spaces, the
same as each user name. I have full access to all shares, directories,
and files.

Here's the script as it stands now (names have been changed to protect
the innocent):

=======================
local
set size=0
call :FindDesktopSize \\server\profiles$
call :findDesktopSize \\server\profile$
echo %size% bytes
goto :EOF

:GetSize
REM Call this subroutine with a directory as the only parameter.
REM Find the size of the files in it in bytes (not including
subdirectories).
REM Add this to the variable SIZE.
for /f "tokens=3" %%i in ('dir /-c "%1" ^| find "File(s)"') do (
set /a size+=%%i
)
goto :EOF

:PushDir
REM Call this subroutine with a directory as the only parameter.
REM Push into this directory, call GetSize, then push into each
subdirectory
REM (make a recursive call to this subroutine). Finally, pop out of the
REM directory.
pushd "%1"
call :GetSize .
for /d %%i in (*) do call :PushDir "%%i"
popd
goto :EOF

:FindDesktopSize
REM Call this subroutine with a profile share as the only parameter. Get
a list
REM of directories in the share, then PushDir against each
REM share\directory\desktop.
for /d %%i in (%1\*) do call :PushDir %%i\desktop
:goto EOF
==========================

Here's some sample output (same note about names):

============================
H>size.cmd

H>setlocal

H>set size=0

H>call :FindDesktopSize \\server\profiles$

H>REM Call this subroutine with a profile share as the only parameter.
Get a list

H>REM of directories in the share, then PushDir against each

H>REM share\directory\desktop.

H>for / %i in (\\server\profiles$\*) do call :PushDir %i\desktop

H>call :PushDir \\server\profiles$\user1\desktop

H>REM Call this subroutine with a directory as the only parameter.

H>REM Push into this directory, call GetSize, then push into each
subdirectory

H>REM (make a recursive call to this subroutine). Finally, pop out of
the

H>REM directory.

H>pushd "\\server\profiles$\user1\desktop"

Y>call :GetSize .

Y>REM Call this subroutine with a directory as the only parameter.

Y>REM Find the size of the files in it in bytes (not including
subdirectories).

Y>REM Add this to the variable SIZE.

Y>for /F "tokens=3" %i in ('dir /-c "." | find "File(s)"') do (set /a
size+=%i )

Y>(set /a size+=5225237 )

Y>goto :EOF

Y>for / %i in (*) do call :PushDir "%i"

Y>popd

H>goto :EOF

H>call :PushDir \\server\profiles$\user2\desktop

H>REM Call this subroutine with a directory as the only parameter.

H>REM Push into this directory, call GetSize, then push into each
subdirectory

H>REM (make a recursive call to this subroutine). Finally, pop out of
the

H>REM directory.

H>pushd "\\server\profiles$\user2\desktop"

Y>call :GetSize .

Y>REM Call this subroutine with a directory as the only parameter.

Y>REM Find the size of the files in it in bytes (not including
subdirectories).

Y>REM Add this to the variable SIZE.

Y>for /F "tokens=3" %i in ('dir /-c "." | find "File(s)"') do (set /a
size+=%i )

Y>(set /a size+=5225237 )

Y>goto :EOF

Y>for / %i in (*) do call :PushDir "%i"

Y>popd

H>goto :EOF

H>call :PushDir \\server\profiles$\user3\desktop

H>REM Call this subroutine with a directory as the only parameter.

H>REM Push into this directory, call GetSize, then push into each
subdirectory

H>REM (make a recursive call to this subroutine). Finally, pop out of
the

H>REM directory.

H>pushd "\\server\profiles$\user3\desktop"

Y>call :GetSize .

Y>REM Call this subroutine with a directory as the only parameter.

Y>REM Find the size of the files in it in bytes (not including
subdirectories).

Y>REM Add this to the variable SIZE.

Y>for /F "tokens=3" %i in ('dir /-c "." | find "File(s)"') do (set /a
size+=%i )

Y>(set /a size+=5225237 )

Y>goto :EOF

Y>for / %i in (*) do call :PushDir "%i"

Y>popd

H>goto :EOF
=======================
....etc...


Notice how size is always incremented by 5225237 bytes? I don't
understand why this is. (I'm not sure what directory I may have that is
exactly that size.) I've also seen elsewhere in the output that Desktop
subdirectories are being pushed to correctly, but still the wrong value
of 5225237 is what is added to SIZE.

I do notice that the FOR command from the PushDir subroutine is getting
its "/D" chopped into "/". Why is this?
 
Yeah, I'd gotten that, but then getting it for each subdirectory,
parsing it, and adding them all together didn't seem to want to work for
me...

It works using /s as the DIR /s command gives you the total at the end.

for /f "tokens=3" %%a in ('dir /s^|find "File(s)"') do set size=%%a
 
foxidrive said:
It works using /s as the DIR /s command gives you the total at the
end.

for /f "tokens=3" %%a in ('dir /s^|find "File(s)"') do set size=%%a

Oh, I see what you're getting at. It'll keep overwriting those
intermediate "File(s)" lines until the last one, which will always be
the total amount.

Hmm, this has promise... Lemme see if I can get it to work with the rest
of it...
 
David Trimboli said:
Oh, I see what you're getting at. It'll keep overwriting those
intermediate "File(s)" lines until the last one, which will always be
the total amount.

Hmm, this has promise... Lemme see if I can get it to work with the
rest of it...


Argh! I finally got the thing to work, but... the file sizes are too
big! They go over the 32-bit limit of integer math in the SET command.
For instance, one person has 6100066249 bytes on his desktop. Oy.

In case anyone is interested (or if you can find a way around the
problem), here's the script as it was working (names have been changed
to protect the innocent) (watch out for line wraps!):

=========
@echo off
echo Calculating total size of profile desktops.
echo This will take a few minutes...
setlocal enabledelayedexpansion
set /a size=0
for /d %%i in (\\server\profiles$\*) do (
for /f "tokens=3" %%j in ('2^>nul dir /s /-c %%i\desktop ^| find
"File(s)"') do (
set desktopsize=%%j
)
set /a size+=!desktopsize!
)
set firstsize=%size%
set /a size=0
for /d %%i in (\\server\profile$\*) do (
for /f "tokens=3" %%j in ('dir /s /-c %%i\desktop ^| find "File(s)"')
do (
set desktopsize=%%j
)
set /a size+=!desktopsize!
)
set /a finalsize=(%firstsize + %size%)/1048576
echo Total size of desktop folders: %finalsize% MB
=====
 
David said:
Argh! I finally got the thing to work, but... the file sizes are too
big! They go over the 32-bit limit of integer math in the SET command.
For instance, one person has 6100066249 bytes on his desktop. Oy.

In case anyone is interested (or if you can find a way around the
problem), here's the script as it was working (names have been changed
to protect the innocent) (watch out for line wraps!):

=========
@echo off
echo Calculating total size of profile desktops.
echo This will take a few minutes...
setlocal enabledelayedexpansion
set /a size=0
for /d %%i in (\\server\profiles$\*) do (
for /f "tokens=3" %%j in ('2^>nul dir /s /-c %%i\desktop ^| find
"File(s)"') do (
set desktopsize=%%j
)
set /a size+=!desktopsize!
)
set firstsize=%size%
set /a size=0
for /d %%i in (\\server\profile$\*) do (
for /f "tokens=3" %%j in ('dir /s /-c %%i\desktop ^| find "File(s)"')
do (
set desktopsize=%%j
)
set /a size+=!desktopsize!
)
set /a finalsize=(%firstsize + %size%)/1048576
echo Total size of desktop folders: %finalsize% MB
=====

You could try this.

@echo off
setlocal
echo Calculating total size of profile desktops.
echo This will take a few minutes...
set t="%temp%".\tmp
echo> %t%.vbs filespec = "\\server\profiles$\"
echo>>%t%.vbs Set fso = CreateObject("Scripting.FileSystemObject")
echo>>%t%.vbs Set f = fso.GetFolder(filespec)
echo>>%t%.vbs Wscript.Echo "set size=" + cStr(Int(f.size/1048576))
cscript /nologo %t%.vbs>%t%.bat
del %t%.vbs
call %t%.bat
del %t%.bat
echo Total size of desktop folders: %size% MB
 
Todd Vargo said:
You could try this.

@echo off
setlocal
echo Calculating total size of profile desktops.
echo This will take a few minutes...
set t="%temp%".\tmp
echo> %t%.vbs filespec = "\\server\profiles$\"
echo>>%t%.vbs Set fso = CreateObject("Scripting.FileSystemObject")
echo>>%t%.vbs Set f = fso.GetFolder(filespec)
echo>>%t%.vbs Wscript.Echo "set size=" + cStr(Int(f.size/1048576))
cscript /nologo %t%.vbs>%t%.bat
del %t%.vbs
call %t%.bat
del %t%.bat
echo Total size of desktop folders: %size% MB

Probably the best approach. I was thinking of dividing the individual size
values by, say, 1000 or 1000000 to give the total size in KB or MB, but
there is always the possibility of a large number of small files showing up
as having a total size of zero.

/Al
 
Todd Vargo said:
You could try this.

@echo off
setlocal
echo Calculating total size of profile desktops.
echo This will take a few minutes...
set t="%temp%".\tmp
echo> %t%.vbs filespec = "\\server\profiles$\"
echo>>%t%.vbs Set fso = CreateObject("Scripting.FileSystemObject")
echo>>%t%.vbs Set f = fso.GetFolder(filespec)
echo>>%t%.vbs Wscript.Echo "set size=" + cStr(Int(f.size/1048576))
cscript /nologo %t%.vbs>%t%.bat
del %t%.vbs
call %t%.bat
del %t%.bat
echo Total size of desktop folders: %size% MB


You're probably right. I'll give it a shot under VBScript.
 
David Trimboli said:
We've got a series of roaming profiles on \\server\profiles$ , and
they're asking me to get the total size of all Desktop folders (in
preparation for deploying Desktop Folder Redirection). I'm looking for
a quick way to determine this number. The script is proving trickier
than I'd thought. Any advice?

In case anyone is interested, here is the final (working) VBscript I
wrote:


Option Explicit
On Error Goto 0

Const intMegaByte = 1048576

Dim intTotalSize

Wscript.StdOut.WriteLine "Calculating total size of all profile
desktops."
Wscript.StdOut.WriteLine "This will take a few minutes..."
intTotalSize = TotalDesktopSize("\\server\profiles$")
intTotalSize = intTotalSize + TotalDesktopSize("\\server\profile$")
Wscript.StdOut.WriteLine
Wscript.StdOut.Write "Total Desktop size on all shares: "
Wscript.StdOut.WriteLine Round(intTotalSize / intMegaByte) & " MB"

Function TotalDesktopSize(strPath)
'Given the path to a profile share, return the size of all desktop
'folders and subfolders, in bytes.

Dim objFileSystem, objProfileShare, colProfiles, objProfile
Dim objDesktopFolder, intSize, strDesktopPath

intSize = 0
Wscript.StdOut.WriteLine strPath
Set objFileSystem = CreateObject("Scripting.FileSystemObject")
Set objProfileShare = objFileSystem.GetFolder(strPath)
Set colProfiles = objProfileShare.SubFolders
For Each objProfile in colProfiles
strDesktopPath = strPath & "\" & objProfile.Name & "\Desktop"
If objFileSystem.FolderExists(strDesktopPath) Then
Set objDesktopFolder = objFileSystem.GetFolder(strDesktopPath)
intSize = intSize + objDesktopFolder.Size
End If
Next
TotalDesktopSize = intSize
End Function
 
Back
Top