{"id":70973,"date":"2004-11-18T10:27:00","date_gmt":"2004-11-18T10:27:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2004\/11\/18\/can-i-use-a-script-to-determine-the-size-of-a-folder-on-a-remote-computer\/"},"modified":"2004-11-18T10:27:00","modified_gmt":"2004-11-18T10:27:00","slug":"can-i-use-a-script-to-determine-the-size-of-a-folder-on-a-remote-computer","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/can-i-use-a-script-to-determine-the-size-of-a-folder-on-a-remote-computer\/","title":{"rendered":"Can I Use a Script to Determine the Size of a Folder on a Remote Computer?"},"content":{"rendered":"<p><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Question\" border=\"0\" alt=\"Hey, Scripting Guy! Question\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" width=\"34\" height=\"34\"> \n<P>Hey, Scripting Guy! Can I use a script to determine the size of a folder on a remote computer?<BR><BR>&#8212; SS<\/P><IMG border=\"0\" alt=\"Spacer\" src=\"https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/05\/spacer.gif\" width=\"5\" height=\"5\"><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Answer\" border=\"0\" alt=\"Hey, Scripting Guy! Answer\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" width=\"34\" height=\"34\"><A href=\"http:\/\/go.microsoft.com\/fwlink\/?linkid=68779&amp;clcid=0x409\"><IMG class=\"farGraphic\" title=\"Script Center\" border=\"0\" alt=\"Script Center\" align=\"right\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/ad.jpg\" width=\"120\" height=\"288\"><\/A> \n<P>Hey, SS. Boy, you\u2019d <I>think<\/I> you\u2019d be able to do that, wouldn\u2019t you? Especially if you\u2019ve glanced through the WMI class Win32_Directory and noticed the property FileSize. Based on that, you might think, \u201cWell, obviously I could just write a WMI script to get the folder size.\u201d In turn you might write a script very similar to this one, which tries to determine the size of the folder C:\\Scripts on the computer atl-ws-01:<\/P><PRE class=\"codeSample\">strComputer = &#8220;atl-ws-01&#8221;\nSet objWMIService = GetObject _\n    (&#8220;winmgmts:&#8221; &amp; &#8220;!\\\\&#8221; &amp; strComputer &amp; &#8220;\\root\\cimv2&#8221;)\nSet colFolders = objWMIService.ExecQuery _\n    (&#8220;Select * from Win32_Directory where Name = &#8221; _\n        &amp; &#8220;&#8216;c:\\\\scripts'&#8221;)\nFor Each objFolder in colFolders\n    Wscript.Echo objFolder.FileSize\nNext\n<\/PRE>\n<P>Unfortunately, this script won\u2019t do you any good, not because of any problem with the scripting code or the scripting syntax, but simply because the FileSize property doesn\u2019t work. It doesn\u2019t matter what folder you connect to and it doesn\u2019t matter whether the folder is on the local computer or a remote computer: the FileSize will always come back Null. <\/P>\n<P><B>Note<\/B>. We should mention that there is also a FileSize property in the CIM_DataFile class, the WMI class used for managing files. <I>That<\/I> FileSize property works; it will actually tell you the size, in bytes, of a file.<\/P>\n<P>So what do we do now? Well, you can always use the FileSystemObject to determine the size of a folder. Here, for example, is a script that tells you the size of our C:\\Scripts folder:<\/P><PRE class=\"codeSample\">Set objFolder = objFSO.GetFolder(&#8220;C:\\Documents and Settings&#8221;)\nSet objFile = objFSO.CreateTextFile(&#8220;c:\\scripts\\folder_size.txt&#8221;)\nWscript.Echo objFolder.Size\n<\/PRE>\n<P>The only problem is that the FileSystemObject is designed to work locally, and the folder you want to size is located on a remote computer. So do we know of a way to work around this problem? Well, we know at least one.<\/P>\n<P>If you\u2019re using Administrative shares (you know, like C$ and D$), then you can get at this folder information by connecting to the appropriate Administrative share. In other words, you can use a script similar to this, which uses the UNC path \\\\atl-ws-01\\C$\\Scripts to get at the C:\\Scripts folder on the remote computer:<\/P><PRE class=\"codeSample\">Set objFSO = CreateObject(&#8220;Scripting.FileSystemObject&#8221;)\nSet objFolder = objFSO.GetFolder(&#8220;\\\\atl-ws-01\\C$\\Scripts&#8221;)\nWscript.Echo objFolder.Size\n<\/PRE>\n<P>This works great, provided you\u2019re using Administrative shares. But what if you\u2019ve disabled those shares on your computers? What then? <\/P>\n<P>Well, to tell you the truth, you might be out of luck, unless you want to run your folder size script as a logon or logoff script. If you have a shared folder of <I>some<\/I> kind on the remote computer, you could also copy the folder size script to the remote machine, run it locally, grab the data, and then delete it again; we showed a similar technique in an earlier <A href=\"http:\/\/null\/technet\/scriptcenter\/resources\/qanda\/nov04\/hey1115.mspx\"><B>Hey, Scripting Guy!<\/B><\/A> column. <\/P>\n<P>And what if you don\u2019t have any shared folders on the remote computer? Unfortunately, we don\u2019t have much in the way of suggestions, other than perhaps searching the Internet for a third-party utility that can retrieve the size of files and folders on a remote machine. <\/P><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey, Scripting Guy! Can I use a script to determine the size of a folder on a remote computer?&#8212; SS Hey, SS. Boy, you\u2019d think you\u2019d be able to do that, wouldn\u2019t you? Especially if you\u2019ve glanced through the WMI class Win32_Directory and noticed the property FileSize. Based on that, you might think, \u201cWell, obviously [&hellip;]<\/p>\n","protected":false},"author":595,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[11,3,12,5],"class_list":["post-70973","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-folders","tag-scripting-guy","tag-storage","tag-vbscript"],"acf":[],"blog_post_summary":"<p>Hey, Scripting Guy! Can I use a script to determine the size of a folder on a remote computer?&#8212; SS Hey, SS. Boy, you\u2019d think you\u2019d be able to do that, wouldn\u2019t you? Especially if you\u2019ve glanced through the WMI class Win32_Directory and noticed the property FileSize. Based on that, you might think, \u201cWell, obviously [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/70973","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/595"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=70973"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/70973\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=70973"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=70973"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=70973"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}