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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with Enumerating Folder information

Status
Not open for further replies.

GregNVMC

IS-IT--Management
Jul 8, 2003
19
0
0
GB
Hi,

I'm a complete newbie to this scripting stuff, but I'm beginning to think it could be really useful!

Please could someone help me? I would like to create a script that will enumerate all the shares on a server and provide details of each of the folders within the share and the total size of the data in each of those folders. I would also like to get the total size of the data within the share?

The results I would like, might look something like:

Server1
Share1 = 26Gb
Folder1 = 1Gb
Folder2 = 1Gb
Share2
Folder1 = 1Gb

etc.

Hope I've explained that OK?

Any help is greatly appreciated.

Many thanks in advance.

Greg
 
OK, this is what I've come up with so far:-

Code:
On Error Resume Next
dim sServer, obj_Share
dim wshNetwork, wshell
dim fso, f
WScript.Timeout = 432000 'Specifies 5 Day script timeout - should be long enough !!!

if Wscript.Arguments.Count <1 then
wscript.echo VBCRLF& &quot;OOPS! You failed to specify a server.&quot; & VBCRLF
ShowUsage
Wscript.quit
end if

if Wscript.Arguments.Count >0 then
if Wscript.Arguments(0)=&quot;/?&quot; then
wscript.echo VBCRLF
ShowUsage
wscript.quit
end if
sServer=Wscript.Arguments(0)
end if

Set wshell=Wscript.Createobject(&quot;Wscript.Shell&quot;)
Set WshNetwork = WScript.CreateObject(&quot;WScript.Network&quot;)
Set fso=CreateObject(&quot;Scripting.FileSystemObject&quot;)
Set f=fso.CreateTextFile(wscript.arguments(0)&&quot;-S.txt&quot;)

f.Writeline &quot;Checking Server &quot; & sServer & &quot; for Shares - &quot; & NOW & vbcrlf
f.Close
'wscript.echo &quot;Checking Server &quot; & sServer & &quot; for Shares.&quot;
set OBJ_Share= GetOBJect(&quot;WinNT://&quot; & sServer &&quot;/lanmanserver&quot;)
if err.number<>0 then
wscript.echo &quot;Error #&quot;&err.number& &quot;: &quot; & err.description
wscript.echo &quot;There was a problem connecting to &quot; &sServer
wscript.quit
else
' wscript.echo &quot;Server Name = &quot; & sServer
For each share in OBJ_Share
set f=fso.OpenTextFile(wscript.arguments(0)&&quot;-S.txt&quot;,8)
wscript.echo &quot;Examining \\&quot; & sServer & &quot;\&quot; & share.name
'Get list of subdirectories
f.WriteLine &quot;============================================================================&quot; & vbcrlf
f.WriteLine &quot; Share Name = &quot; & share.name
f.WriteLine &quot; Share Path = &quot; & share.path
f.WriteLine &quot; Share Size = &quot; & share.size
f.WriteLine &quot; Description = &quot; & share.description & vbcrlf
f.Close
'give file a chance to close before continuing
wscript.sleep 2000
wscript.echo &quot; Checking subfolders...please wait&quot;
GetDirTree &quot;\\&quot; & sServer & &quot;\&quot; & share.name
Next
End If
wscript.echo &quot;See &quot; & sServer & &quot;-S.txt For results&quot;

Set sServer=Nothing
set obj_Share=Nothing
wscript.quit


'//////////////////////////
'/ Get Directory Tree /
'//////////////////////////

Sub GetDirTree(dir)
Dim oFolder,oFolders,item
On Error Resume Next

Set oFolder=fso.GetFolder(dir)
set oFolders=oFolder.SubFolders

' get all sub-folders in this folder
For Each item In oFolders
'wscript.echo item.Path

set f=fso.OpenTextFile(wscript.arguments(0)&&quot;-S.txt&quot;,8)
f.WriteLine &quot;--------------------------------------------------------------------&quot;
f.WriteLine ( vbcrlf & &quot;*** For Path &quot; & CHR(34) & cstr(item.path) & CHR(34) & &quot; The Folder Size is = &quot; & int(item.size / 1048576) & &quot; Mb ***&quot; )
f.WriteLine ( vbcrlf & &quot;*** Folder Permissions ***&quot;)
f.Close
'give file a chance to close before continuing
wscript.sleep 2000

c=wshell.Run(&quot;cmd /c &quot; & &quot;cacls &quot; & CHR(34) & item.Path & CHR(34) & &quot; >>&quot; & sServer & &quot;-S.txt&quot;,0,True)
GetDirTree(item)
Next

End Sub


'//////////////////////////
'/ Show Usage /
'//////////////////////////

Function ShowUsage
wscript.echo &quot;Usage: &quot; & Wscript.ScriptName
wscript.echo &quot;Cscript auditshareperms.vbs [servername]&quot;
wscript.echo &quot; Example: cscript auditshareperms.vbs filesrv01&quot; & vbCrlf
wscript.echo &quot;Cscript auditshareperms.vbs /? will display this help message&quot;

End Function

I'm working on extending the capabilties of the script, as I want it to generate a list of servers in the domain and then list the services running on each remote server.

I'm having difficulties with the line of code:

f.WriteLine &quot; Share Size = &quot; & share.size

I guess this is not a property I can use? How do I find the total space used of the share in question?

Thanks in advance.

Greg
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top