I need a script to find out the number & total size of files based upon the file extention across about 30 servers. I'm searching for mdb files. The script will be run remotely against local drives on these servers. Thanks
On Nov 18, 10:19 am, Tom1 <usernetu...@yahoo.com> wrote:
> I need a script to find out the number & total size of files based > upon the file extention across about 30 servers. I'm searching for mdb > files. The script will be run remotely against local drives on these > servers. Thanks
<warning> <aircode>
with createobject("scripting.filesystemobject") aComputers = split(.opentextfile("D:\Someplace\complist.txt", _ 1).readall, vbnewline) end with
> On Nov 18, 10:19 am, Tom1 <usernetu...@yahoo.com> wrote:
> > I need a script to find out the number & total size of files based > > upon the file extention across about 30 servers. I'm searching for mdb > > files. The script will be run remotely against local drives on these > > servers. Thanks
> <warning> > <aircode>
> with createobject("scripting.filesystemobject") > aComputers = split(.opentextfile("D:\Someplace\complist.txt", _ > 1).readall, vbnewline) > end with
> On Nov 18, 10:43 am, Tom Lavedas <tglba...@cox.net> wrote:
> > On Nov 18, 10:19 am, Tom1 <usernetu...@yahoo.com> wrote:
> > > I need a script to find out the number & total size of files based > > > upon the file extention across about 30 servers. I'm searching for mdb > > > files. The script will be run remotely against local drives on these > > > servers. Thanks
> > <warning> > > <aircode>
> > with createobject("scripting.filesystemobject") > > aComputers = split(.opentextfile("D:\Someplace\complist.txt", _ > > 1).readall, vbnewline) > > end with
> > for i = 0 to nComputers > > nSize = 0 > > nCount = 0 > > Set objWMIService = GetObject("winmgmts:" _ > > & "{impersonationLevel=impersonate}!\\" & _ > > aComputers(i) & "\root\cimv2") > > Set colFiles = objWMIService.ExecQuery _ > > ("Select * from CIM_DataFile where Extension = 'mdb'", , 48) > > For Each objFile in colFiles > > nSize = nSize + objFile.size > > Next > > nCount = nCount + colFiles.count > > aData(i) = Join(Array(aComputers(i), nCount, nSize), ", ") > > Next
> > wsh.echo Join(aData, vbnewline)
> > </aircode> > > </warning>
> > Another warning: CIM_DataFile searches are SLOW. Be prepared to W - > > A - I - T. > > _____________________ > > Tom Lavedas
> Thanks but I get the following error message:
> test.vbs(22, 5) Microsoft VBScript runtime error: Object doesn't > support this property or method: 'size'
I was afraid of that - I keep forgetting what the differences are between Shell.Application and FSO. OK, try this mod ...
set fso = createobject("scripting.filesystemobject") with fso aComputers = split(.opentextfile("D:\Someplace\complist.txt", _ 1).readall, vbnewline) end with
>I need a script to find out the number & total size of files based > upon the file extention across about 30 servers. I'm searching for mdb > files. The script will be run remotely against local drives on these > servers. Thanks
In view of Tom's explicit warning about the slowness of the WMI solution, what's wrong with the humble "dir" command? It can access remote resources and it is *much* faster than WMI.
> On Nov 18, 11:40 am, Tom1 <usernetu...@yahoo.com> wrote:
> > On Nov 18, 10:43 am, Tom Lavedas <tglba...@cox.net> wrote:
> > > On Nov 18, 10:19 am, Tom1 <usernetu...@yahoo.com> wrote:
> > > > I need a script to find out the number & total size of files based > > > > upon the file extention across about 30 servers. I'm searching for mdb > > > > files. The script will be run remotely against local drives on these > > > > servers. Thanks
> > > <warning> > > > <aircode>
> > > with createobject("scripting.filesystemobject") > > > aComputers = split(.opentextfile("D:\Someplace\complist.txt", _ > > > 1).readall, vbnewline) > > > end with
> > > for i = 0 to nComputers > > > nSize = 0 > > > nCount = 0 > > > Set objWMIService = GetObject("winmgmts:" _ > > > & "{impersonationLevel=impersonate}!\\" & _ > > > aComputers(i) & "\root\cimv2") > > > Set colFiles = objWMIService.ExecQuery _ > > > ("Select * from CIM_DataFile where Extension = 'mdb'", , 48) > > > For Each objFile in colFiles > > > nSize = nSize + objFile.size > > > Next > > > nCount = nCount + colFiles.count > > > aData(i) = Join(Array(aComputers(i), nCount, nSize), ", ") > > > Next
> > > wsh.echo Join(aData, vbnewline)
> > > </aircode> > > > </warning>
> > > Another warning: CIM_DataFile searches are SLOW. Be prepared to W - > > > A - I - T. > > > _____________________ > > > Tom Lavedas
> > Thanks but I get the following error message:
> > test.vbs(22, 5) Microsoft VBScript runtime error: Object doesn't > > support this property or method: 'size'
> I was afraid of that - I keep forgetting what the differences are > between Shell.Application and FSO. OK, try this mod ...
> set fso = createobject("scripting.filesystemobject") > with fso > aComputers = split(.opentextfile("D:\Someplace\complist.txt", _ > 1).readall, vbnewline) > end with
> On Nov 18, 11:40 am, Tom1 <usernetu...@yahoo.com> wrote:
> > On Nov 18, 10:43 am, Tom Lavedas <tglba...@cox.net> wrote:
> > > On Nov 18, 10:19 am, Tom1 <usernetu...@yahoo.com> wrote:
> > > > I need a script to find out the number & total size of files based > > > > upon the file extention across about 30 servers. I'm searching for mdb > > > > files. The script will be run remotely against local drives on these > > > > servers. Thanks
> > > <warning> > > > <aircode>
> > > with createobject("scripting.filesystemobject") > > > aComputers = split(.opentextfile("D:\Someplace\complist.txt", _ > > > 1).readall, vbnewline) > > > end with
> > > for i = 0 to nComputers > > > nSize = 0 > > > nCount = 0 > > > Set objWMIService = GetObject("winmgmts:" _ > > > & "{impersonationLevel=impersonate}!\\" & _ > > > aComputers(i) & "\root\cimv2") > > > Set colFiles = objWMIService.ExecQuery _ > > > ("Select * from CIM_DataFile where Extension = 'mdb'", , 48) > > > For Each objFile in colFiles > > > nSize = nSize + objFile.size > > > Next > > > nCount = nCount + colFiles.count > > > aData(i) = Join(Array(aComputers(i), nCount, nSize), ", ") > > > Next
> > > wsh.echo Join(aData, vbnewline)
> > > </aircode> > > > </warning>
> > > Another warning: CIM_DataFile searches are SLOW. Be prepared to W - > > > A - I - T. > > > _____________________ > > > Tom Lavedas
> > Thanks but I get the following error message:
> > test.vbs(22, 5) Microsoft VBScript runtime error: Object doesn't > > support this property or method: 'size'
> I was afraid of that - I keep forgetting what the differences are > between Shell.Application and FSO. OK, try this mod ...
> set fso = createobject("scripting.filesystemobject") > with fso > aComputers = split(.opentextfile("D:\Someplace\complist.txt", _ > 1).readall, vbnewline) > end with
> On Nov 18, 11:58 am, Tom Lavedas <tglba...@cox.net> wrote:
> > On Nov 18, 11:40 am, Tom1 <usernetu...@yahoo.com> wrote:
> > > On Nov 18, 10:43 am, Tom Lavedas <tglba...@cox.net> wrote:
> > > > On Nov 18, 10:19 am, Tom1 <usernetu...@yahoo.com> wrote:
> > > > > I need a script to find out the number & total size of files based > > > > > upon the file extention across about 30 servers. I'm searching for mdb > > > > > files. The script will be run remotely against local drives on these > > > > > servers. Thanks
> > > > <warning> > > > > <aircode>
> > > > with createobject("scripting.filesystemobject") > > > > aComputers = split(.opentextfile("D:\Someplace\complist.txt", _ > > > > 1).readall, vbnewline) > > > > end with
> On Nov 18, 11:58 am, Tom Lavedas <tglba...@cox.net> wrote:
> > On Nov 18, 11:40 am, Tom1 <usernetu...@yahoo.com> wrote:
> > > On Nov 18, 10:43 am, Tom Lavedas <tglba...@cox.net> wrote:
> > > > On Nov 18, 10:19 am, Tom1 <usernetu...@yahoo.com> wrote:
> > > > > I need a script to find out the number & total size of files based > > > > > upon the file extention across about 30 servers. I'm searching for > > > > > mdb > > > > > files. The script will be run remotely against local drives on > > > > > these > > > > > servers. Thanks
> > > > <warning> > > > > <aircode>
> > > > with createobject("scripting.filesystemobject") > > > > aComputers = split(.opentextfile("D:\Someplace\complist.txt", _ > > > > 1).readall, vbnewline) > > > > end with
As you can see, all I need is the 109 files & the 324,595,215 bytes in the output (not interested in the numbers before that). Is this doable?
======
Sure is - with a little batch file (which is often frowned upon in this newsgroup):
[1] @echo off [2] for /F "tokens=3" %%a in ('dir \\server1\h$:\*.ppt /s ^| find " File(s) "') do set Total=%%a [3] echo Total=%Total%
You need to unwrap wrapped lines (if necessary) and remove the line numbers. If desired then you can expand the above batch script so that it scans a whole set of servers and adds up the numbers to a grand total.
> Sure is - with a little batch file (which is often frowned upon in this > newsgroup):
> [1] @echo off > [2] for /F "tokens=3" %%a in ('dir \\server1\h$:\*.ppt /s ^| find " File(s) > "') do set Total=%%a > [3] echo Total=%Total%
> You need to unwrap wrapped lines (if necessary) and remove the line numbers. > If desired then you can expand the above batch script so that it scans a > whole set of servers and adds up the numbers to a grand total.
My personal choice would be something like this...
@echo off setlocal for /F "tokens=1,3" %%a in ( 'dir dir \\server1\h$\*.mdb /s /-c^| find " File(s)"' ) do set /a FileCount=%%a,Total=%%b echo %FileCount% files totaling %Total% bytes
Pegusus: Note the /-C switch to remove the commas from the listing. Also, the colon after the share name does not belong. _____________________ Tom Lavedas
> Sure is - with a little batch file (which is often frowned upon in this > newsgroup):
> [1] @echo off > [2] for /F "tokens=3" %%a in ('dir \\server1\h$:\*.ppt /s ^| find " > File(s) > "') do set Total=%%a > [3] echo Total=%Total%
> You need to unwrap wrapped lines (if necessary) and remove the line > numbers. > If desired then you can expand the above batch script so that it scans a > whole set of servers and adds up the numbers to a grand total.
My personal choice would be something like this...
@echo off setlocal for /F "tokens=1,3" %%a in ( 'dir dir \\server1\h$\*.mdb /s /-c^| find " File(s)"' ) do set /a FileCount=%%a,Total=%%b echo %FileCount% files totaling %Total% bytes
Pegusus: Note the /-C switch to remove the commas from the listing. Also, the colon after the share name does not belong. _____________________ Tom Lavedas
==========
Thanks for picking up the extra colon. It was actually the OP's doing but I admit that I overlooked it. In your code there is an oversight too - the two "dir dir" commands should proably be reduced to just one.
I'm aware of the /-c switch for the "dir" command - it would come in handy if the OP decided to total up the numbers from several servers. Conversely - why would you use the /a switch for the "set" command? You're not calculating any arithmetic expression.
I note with concern that we're deep into a batch file discussion even though we're in a VB Scripting group. I can feel the flames scorching my backside.
> > "Tom1" <usernetu...@yahoo.com> wrote in message
> >{snip}
> > Sure is - with a little batch file (which is often frowned upon in this > > newsgroup):
> > [1] @echo off > > [2] for /F "tokens=3" %%a in ('dir \\server1\h$:\*.ppt /s ^| find " > > File(s) > > "') do set Total=%%a > > [3] echo Total=%Total%
> > You need to unwrap wrapped lines (if necessary) and remove the line > > numbers. > > If desired then you can expand the above batch script so that it scans a > > whole set of servers and adds up the numbers to a grand total.
> My personal choice would be something like this...
> @echo off > setlocal > for /F "tokens=1,3" %%a in ( > 'dir dir \\server1\h$\*.mdb /s /-c^| find " File(s)"' > ) do set /a FileCount=%%a,Total=%%b > echo %FileCount% files totaling %Total% bytes
> Pegusus: Note the /-C switch to remove the commas from the listing. > Also, the colon after the share name does not belong. > _____________________ > Tom Lavedas
> ==========
> Thanks for picking up the extra colon. It was actually the OP's doing but I > admit that I overlooked it. In your code there is an oversight too - the two > "dir dir" commands should proably be reduced to just one.
> I'm aware of the /-c switch for the "dir" command - it would come in handy > if the OP decided to total up the numbers from several servers. Conversely - > why would you use the /a switch for the "set" command? You're not > calculating any arithmetic expression.
> I note with concern that we're deep into a batch file discussion even though > we're in a VB Scripting group. I can feel the flames scorching my backside.
The group has tuned this thread out already, I would guess.
The double 'dir' is a c&p problem - thanks for catching that.
I removed the commas to get the complete number. Otherwise, it would have just collected the most significant grouping in the US. You're in an locale that uses dots, I believe, so what you posted will work as expected. Here in the US, the standard comma separator causes problems because it is also a command line delimiter.
Finally, I used the /A so I could collect both the file count and size numbers in one SET statement using the comma 'expression separator' (last operand in the SET help listing). (That's another reasons for the /A switch in the SET.) _____________________ Tom Lavedas
On Nov 18, 12:14 pm, Tom1 <usernetu...@yahoo.com> wrote:
> Still not working -- test.vbs(24, 5) Microsoft VBScript runtime error: > File not found
OK. I give up on that approach. It's too slow anyway. However, you can do it in VBS with a recursive search using FSO via the administrative share, as we did with the command line DIR.
Something like this ...
set ofs = createobject("scripting.filesystemobject") aComputers = split(fso.opentextfile("D:\Someplace\complist.txt", _ 1).readall, vbnewline)
for i = 0 to nComputers nSize = 0 nCount = 0 dpath = "\\" & aComputers(i) & "\C$\" getSize dPath, "mdb", nCount, nSize, fso aData(i) = Join(Array(aComputers(i), nCount, nSize), ", ") Next
wsh.echo Join(aData, vbnewline)
Sub getSize(sPath, sExt, nCount, nSize, ofs) Dim s s = "" With ofs.GetFolder(sPath) getFileSize .files, sExt, nCount, nSize, fso if .SubFolders.Count > 0 Then For each folder in .SubFolders getSize sPath & "\" & folder.Name, sExt, nCount, nSize, ofs Next End if End With End Sub
Sub getFileSize(cFiles, sExt, nCount, nSize, fso) For each file in cFiles if lcase(ofs.getExtensionName(file.name)) = lcase(sExt) then nCount = nCount + 1 nSize = nSize + file.size end if Next end sub _____________________ Tom Lavedas
> I note with concern that we're deep into a batch file discussion even > though we're in a VB Scripting group. I can feel the flames scorching my > backside.
Seems to me that this batch file will be called from a VBScript and perhaps its output will be redirected to the same VBScript, all within a Microsoft OS. To me that is a good enough reason to have this discussion nere, on how to get accurate results to the OP's need without having to wait for the slow WMI processing that few would quibble with discussing here.
> > "Tom1" <usernetu...@yahoo.com> wrote in message
> >{snip}
> > Sure is - with a little batch file (which is often frowned upon in this > > newsgroup):
> > [1] @echo off > > [2] for /F "tokens=3" %%a in ('dir \\server1\h$:\*.ppt /s ^| find " > > File(s) > > "') do set Total=%%a > > [3] echo Total=%Total%
> > You need to unwrap wrapped lines (if necessary) and remove the line > > numbers. > > If desired then you can expand the above batch script so that it scans a > > whole set of servers and adds up the numbers to a grand total.
> My personal choice would be something like this...
> @echo off > setlocal > for /F "tokens=1,3" %%a in ( > 'dir dir \\server1\h$\*.pst /s /-c^| find " File(s)"' > ) do set /a FileCount=%%a,Total=%%b > echo %FileCount% files totaling %Total% bytes
> Pegusus: Note the /-C switch to remove the commas from the listing. > Also, the colon after the share name does not belong. > _____________________ > Tom Lavedas
> ==========
> Thanks for picking up the extra colon. It was actually the OP's doing but I > admit that I overlooked it. In your code there is an oversight too - the two > "dir dir" commands should proably be reduced to just one.
> I'm aware of the /-c switch for the "dir" command - it would come in handy > if the OP decided to total up the numbers from several servers. Conversely - > why would you use the /a switch for the "set" command? You're not > calculating any arithmetic expression.
> I note with concern that we're deep into a batch file discussion even though > we're in a VB Scripting group. I can feel the flames scorching my backside.- Hide quoted text -
> - Show quoted text -
I ran the above script against a 2TB drive. Here is the script output (after 2 hours & 55 minutes of parsing the data):
Invalid number. Numbers are limited to 32-bits of precision. Invalid number. Numbers are limited to 32-bits of precision. Invalid number. Numbers are limited to 32-bits of precision. 1667 files totaling 15508480 bytes
The above results (1667 files totaling 15508480 bytes) are not correct. The correct numbers are:
Total bytes: 591,657,988,611 (577,791,004.50 KB) (564,249.03 MB) Total files: 1670 Average size: 354,286,220 bytes Smallest: 0 bytes Largest: 6,998,934,528 bytes
> > "Tom1" <usernetu...@yahoo.com> wrote in message
> >{snip}
> > Sure is - with a little batch file (which is often frowned upon in this > > newsgroup):
> > [1] @echo off > > [2] for /F "tokens=3" %%a in ('dir \\server1\h$:\*.ppt /s ^| find " > > File(s) > > "') do set Total=%%a > > [3] echo Total=%Total%
> > You need to unwrap wrapped lines (if necessary) and remove the line > > numbers. > > If desired then you can expand the above batch script so that it scans a > > whole set of servers and adds up the numbers to a grand total.
> My personal choice would be something like this...
> @echo off > setlocal > for /F "tokens=1,3" %%a in ( > 'dir dir \\server1\h$\*.pst /s /-c^| find " File(s)"' > ) do set /a FileCount=%%a,Total=%%b > echo %FileCount% files totaling %Total% bytes
> Pegusus: Note the /-C switch to remove the commas from the listing. > Also, the colon after the share name does not belong. > _____________________ > Tom Lavedas
> ==========
> Thanks for picking up the extra colon. It was actually the OP's doing but > I > admit that I overlooked it. In your code there is an oversight too - the > two > "dir dir" commands should proably be reduced to just one.
> I'm aware of the /-c switch for the "dir" command - it would come in handy > if the OP decided to total up the numbers from several servers. > Conversely - > why would you use the /a switch for the "set" command? You're not > calculating any arithmetic expression.
> I note with concern that we're deep into a batch file discussion even > though > we're in a VB Scripting group. I can feel the flames scorching my > backside.- Hide quoted text -
> - Show quoted text -
I ran the above script against a 2TB drive. Here is the script output (after 2 hours & 55 minutes of parsing the data):
Invalid number. Numbers are limited to 32-bits of precision. Invalid number. Numbers are limited to 32-bits of precision. Invalid number. Numbers are limited to 32-bits of precision. 1667 files totaling 15508480 bytes
The above results (1667 files totaling 15508480 bytes) are not correct. The correct numbers are:
Total bytes: 591,657,988,611 (577,791,004.50 KB) (564,249.03 MB) Total files: 1670 Average size: 354,286,220 bytes Smallest: 0 bytes Largest: 6,998,934,528 bytes
==============
I'm not surprised. When running such programs, whether as batch files or as VB Script files, one needs to size up the numbers expected, then adjust the code so that one stays within acceptable bounds. When it comes to disk space then I would restrict myself to MBytes. No point in going down to Bytes.
I would also run a test on a medium-size disk to determine which is faster, a VB Script based on the File System Object or a batch file. And if you want quick results then a batch file invoked remotely, using psexec.exe, will beat the lot while creating negligible network traffic.
>> Sure is - with a little batch file (which is often frowned upon in this >> newsgroup):
>> [1] @echo off >> [2] for /F "tokens=3" %%a in ('dir \\server1\h$:\*.ppt /s ^| find " >> File(s) >> "') do set Total=%%a >> [3] echo Total=%Total%
>> You need to unwrap wrapped lines (if necessary) and remove the line >> numbers. >> If desired then you can expand the above batch script so that it scans a >> whole set of servers and adds up the numbers to a grand total.
> My personal choice would be something like this...
> @echo off > setlocal > for /F "tokens=1,3" %%a in ( > 'dir dir \\server1\h$\*.mdb /s /-c^| find " File(s)"' > ) do set /a FileCount=%%a,Total=%%b > echo %FileCount% files totaling %Total% bytes
> Pegusus: Note the /-C switch to remove the commas from the listing. > Also, the colon after the share name does not belong. > _____________________ > Tom Lavedas
> ==========
> Thanks for picking up the extra colon. It was actually the OP's doing but > I admit that I overlooked it. In your code there is an oversight too - the > two "dir dir" commands should proably be reduced to just one.
> I'm aware of the /-c switch for the "dir" command - it would come in handy > if the OP decided to total up the numbers from several servers. > Conversely - why would you use the /a switch for the "set" command? You're > not calculating any arithmetic expression.
> I note with concern that we're deep into a batch file discussion even > though we're in a VB Scripting group. I can feel the flames scorching my > backside.
Then I need not say anything about it... ;-)
Of course, this type of thing would be even easier in Powershell (another non-vbscript language), in which files and folders are objects with properties like "size", and in which numbers with more than 9 digits overflow.