Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

WMI to check file/dir size on remote machine 1

Status
Not open for further replies.

mwiner

IS-IT--Management
Oct 24, 2002
266
US
I was wondering if somebody could point me to the right class and property to find the file size or directory size on a remote machine.

I have looked into Win32_Directory but I don't think it gave me the size of the directory. At least not that I could find.

I know how to get disk size information but I need to look at a specific dir or the two files that reside in it.

Thanks!

-Matt
 
I would use the FIleSystemObject. It will tell you the size of a folder or directory.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
FileSystemObject is in VB right?

I need to run the script on my local machine and gather information on the remote machine. The biggest issue is that it is outside my domain so I need to provide alternate credentials which I can do with WMI.
 
Take a look at the WshNetwork.MapNetworkDrive method and at the Size property of the Folder object.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
ok. Thank you.

I am trying to stay away from mapping network drives and limit as much VB as I can. I really need this to be done via WMI.

But thanks for the suggestions and I will keep them in mind.

 
Be aware that WMI is slooooow when dealing with (remote or not) file systems.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
I am fully aware of this and I have had no issues at all. I am using WMI very succesfully for Microsoft Exchange 2003 Queue monitoring.
 
Hello mwiner,

For a specific file with fully qualified path, you can do this.
Code:
shost="a0b1c2"
filespec="d:\test\abc.def"

set svc=getobject("winmgmts:\\" & shost & "\root\cimv2")
set ofile=svc.get("cim_datafile.name='" & filespec & "'")
wscript.echo ofile.name & vbcrlf & ofile.filesize & " bytes"
set ofile=nothing : set svc=nothing
For a directory, to get its "size", you have to sum over files inside and expand subdirectories etc.

regards - tsuji
 
As long as the folder you care about is shared, then there is no need to map a drive at all. This is much simpler than using WMI:

Option Explicit
Dim oFSO:Set oFSO = CreateObject("Scripting.FileSystemObject")
Dim oFolder
Set oFolder = oFSO.GetFolder("\\RemoteComputer\SharedFolder")
WScript.Echo oFolder.Size

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Tsuji,

Thank you! cim_datafile. Who knew... This whole time I was looking in the Win32_ classes.




TomThumb,
This directory is NOT shared and I do not have any intention of sharring it or mapping a drive to it. Plus the fact that it is outside my domain. I know that a mapped drive and using FSO might be easier. But the ONLY hard part out WMI is just finding the class and property of the data you are looking for. After that, getting the data is so easy you don't even know what to do with yourself. Plus the amount of detail and type of data that is gathered is amazing. I am not just saying for file sizes, etc. I am talking about EVERYTHING you wanted to know about ANY part of the machine. There is data in there that you can't even get to directly in windows.



But thank you all for your suggestions

-Matt
 
Hello,

Could I have your method please because I have the same problem but ... No solution yet

Thanks in advance.
I use CIM_datafile but no success : I Have NULL like result :(
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top