Hey all,

I need to write a simple script that will enumerate all of the shares
on our file servers, and the number of user accounts with permissions
to each share. The purpose is to evaluate which shares can be deleted
to free up disk space by deleting shares with fewer than 10 users.

I have found some simple VBScript and JScript code that will enumerate
all of the shares on a given server like so:

' Begin code snippit
set objFs = GetObject("WinNT://" & strServer &
"/LanmanServer,FileService")

For Each objShare In objFs
strList = strList & vbCr & LCase(objShare.name) & vbTab &
UCase(objShare.Description)
Next
' End code snippit

My problem is that I need to know what other class members/methods are
available for the "FileService" (instanced as objFs) In the example
above, we use objShare.name and objShare.Description during the loop.
In which documentation would I find a list of the other class
methods/variables for objShare? I am at wits end, just trying to find
the documentation

Thanks in advance
Tim

Re: Enumerating network shares by Steven

Steven
Fri Oct 07 06:44:00 CDT 2005

WSH documentation
http://surl.co.uk/?2004

Original URL:
http://www.microsoft.com/downloads/details.aspx?FamilyID=01592c48-207d-4be1-
8a76-1c4099d7bbb9&DisplayLang=en

--
Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!

<juicy_killa@hotmail.com> wrote in message
news:1128673126.688383.12520@g14g2000cwa.googlegroups.com...
> Hey all,
>
> I need to write a simple script that will enumerate all of the shares
> on our file servers, and the number of user accounts with permissions
> to each share. The purpose is to evaluate which shares can be deleted
> to free up disk space by deleting shares with fewer than 10 users.
>
> I have found some simple VBScript and JScript code that will enumerate
> all of the shares on a given server like so:
>
> ' Begin code snippit
> set objFs = GetObject("WinNT://" & strServer &
> "/LanmanServer,FileService")
>
> For Each objShare In objFs
> strList = strList & vbCr & LCase(objShare.name) & vbTab &
> UCase(objShare.Description)
> Next
> ' End code snippit
>
> My problem is that I need to know what other class members/methods are
> available for the "FileService" (instanced as objFs) In the example
> above, we use objShare.name and objShare.Description during the loop.
> In which documentation would I find a list of the other class
> methods/variables for objShare? I am at wits end, just trying to find
> the documentation
>
> Thanks in advance
> Tim
>



Re: Enumerating network shares by TDM

TDM
Fri Oct 07 10:27:35 CDT 2005


<juicy_killa@hotmail.com> wrote in message
news:1128673126.688383.12520@g14g2000cwa.googlegroups.com...
> Hey all,
>
> I need to write a simple script that will enumerate all of the shares
> on our file servers, and the number of user accounts with permissions
> to each share. The purpose is to evaluate which shares can be deleted
> to free up disk space by deleting shares with fewer than 10 users.
>
> I have found some simple VBScript and JScript code that will enumerate
> all of the shares on a given server like so:
>
> ' Begin code snippit
> set objFs = GetObject("WinNT://" & strServer &
> "/LanmanServer,FileService")
>
> For Each objShare In objFs
> strList = strList & vbCr & LCase(objShare.name) & vbTab &
> UCase(objShare.Description)
> Next
> ' End code snippit
>
> My problem is that I need to know what other class members/methods are
> available for the "FileService" (instanced as objFs) In the example
> above, we use objShare.name and objShare.Description during the loop.
> In which documentation would I find a list of the other class
> methods/variables for objShare? I am at wits end, just trying to find
> the documentation
>
> Thanks in advance
> Tim
>

You might also want to explore Win32_Share using WMI. I trust your servers
are Win2K or greater ?, and the user running this script has admin rights
on the servers ? I grabbed this function from a much larger script I wrote
to look for openshares on the network. It also contains a function to
enumerate
the user accounts and access rights for each user per share. If interested,
I can
send via e-mail if you like. Again, using WMI.

Function getNetShares(strHostName)

Dim objWMIService
Dim colShares
Dim objShare
Dim strMyMsg

On Error Resume Next

Set objWMIService = GetObject("winmgmts:" &
"{impersonationLevel=impersonate,authenticationLevel=Default}!\\" &
strHostName & "\root\cimv2")
Set colShares = objWMIService.ExecQuery("Select * from Win32_Share", , 48)

For Each objShare in colShares
strMyMsg = "Share Name: " & vbTab & objShare.Name & vbCrLf
strMyMsg = strMyMsg & "Share Caption: " & vbTab & objShare.Caption &
vbCrLf
strMyMsg = strMyMsg & "Share Path: " & vbTab & objShare.Path & vbCrLf
strMyMsg = strMyMsg & "Share Type: " & vbTab &
getShareType(objShare.Type) & vbCrLf
WScript.Echo strMyMsg
Next

Set objWMIService = Nothing
Set colShares = Nothing

getNetShares = Err.Number

End Function

My personal favorite for finding what you request in WMI is the WMI object
browser
from M$. Watch for line wrap ...

http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=6430F853-1120-48DB-8CC5-F2ABDC3ED314

TDM



Re: Enumerating network shares by juicy_killa

juicy_killa
Fri Oct 07 11:37:59 CDT 2005

Actually, the script you mention above sounds like exactly what I am
looking for. I would be very interested to see it (the email account
listed for my name is a valid account)

Although I believe I found a working tool, srvcheck.exe from the
Windows 2003 server resource kit. It claims to enumerate all shares on
a specific server, with permissions, but I would still love to see how
it could be done in a script.

Thank you
Tim


Re: Enumerating network shares by de

de
Sat Oct 08 03:44:42 CDT 2005

This is a work in progress


'
'
' Name:
'
'
'
' ShowShareAccess.vbs
'
'
'
' Description:
'
'
'
' Run this script from the command line on a machine and it will create a
report that '
' shows all of the non-administrative shares on that machine, the
physical path for each '
' share, the description (if entered) and a summary of all of the
accounts that have '
' permissions (either inherited or explicit) associated with the share
and the physical '
' path.
'
'
'
' Audit:
'
'
'
' 2005-09-27 jdeg original code
'
'
'

if wscript.arguments.count > 0 then
verbose = wscript.Arguments(0) = "-v"
else
verbose = false
end if

set wso = CreateObject("Wscript.Shell")

set aceflags = CreateObject("Scripting.Dictionary")
aceflags(1) = "OBJECT_INHERIT_ACE"
aceflags(2) = "CONTAINER_INHERIT_ACE"
aceflags(4) = "NO_PROPOGATE_INHERIT_ACE"
aceflags(8) = "INHERIT_ONLY_ACE"
aceflags(16) = "INHERITED_ACE"

set acetypes = CreateObject("Scripting.Dictionary")
acetypes(0) = "Access Allowed"
acetypes(1) = "Access Denied"
acetypes(2) = "Audit"

set rights = CreateObject("Scripting.Dictionary")
rights(&h00000001) = "FILE_LIST_DIRECTORY"
rights(&h00000002) = "FILE_ADD_FILE"
rights(&h00000004) = "FILE_ADD_SUBDIRECTORY"
rights(&h00000008) = "FILE_READ_EA"
rights(&h00000010) = "FILE_WRITE_EA"
rights(&h00000020) = "FILE_TRAVERSE"
rights(&h00000040) = "FILE_DELETE_CHILD"
rights(&h00000080) = "FILE_READ_ATTRIBUTES"
rights(&h00000100) = "FILE_WRITE_ATTRIBUTES"
rights(&h00010000) = "DELETE"
rights(&h00020000) = "READ_CONTROL"
rights(&h00040000) = "WRITE_DAC"
rights(&h00080000) = "WRITE_OWNER"
rights(&h00100000) = "SYNCHRONIZE"

set summary = CreateObject("Scripting.Dictionary")
summary(&h1f01ff) = "FULL"
summary(&h1301bf) = "CHANGE"
summary(&h1200a9) = "READ"

set shares = CreateObject("System.Collections.SortedList")

'get a collection of all of the non-administrative (type=0) shares

Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set colShares = objWMIService.ExecQuery("Select * from Win32_Share where
Type = 0",,48)

'build a list of all the share information

For Each item in colShares
share = item.Name
path = item.Path
desc = item.Description
shares.Add share,Array(path,desc)
Next

'dump out the report

title = "Access Lists for \\" &
wso.ExpandEnvironmentStrings("%COMPUTERNAME%")
wscript.echo title & vbcrlf & String(len(title),"-")

for i = 0 to shares.Count - 1
share = shares.GetKey(i)
value = shares.GetByIndex(i)
path = value(0)
desc = value(1)
wscript.echo vbcrlf & "SHARE: " & share & vbcrlf & " PATH: " &
path,iif(desc<> "",vbcrlf & " DESC: "&desc,"")
DoShare share,verbose
DoFolder path,verbose
next

'
'
' dump the access list entries for a folder
'
'
'

Function DoFolder ( target , verbose )
Set wmi = GetObject("winmgmts:")
Set sec = wmi.Get("Win32_LogicalFileSecuritySetting='" & target & "'")
DumpACL "(F)",sec, verbose
End Function

'
'
' dump the access list entries for a share
'
'
'

Function DoShare ( target , verbose )
Set wmi = GetObject("winmgmts:")
Set sec = wmi.Get("Win32_LogicalShareSecuritySetting='" & target & "'")
DumpACL "(S)",sec, verbose
End Function

'
'
' dump the access list entries
'
'
'

Function DumpACL ( ttype , sec , verbose )

dim sd
dim retval: retval = sec.GetSecurityDescriptor(sd)
dim ace
dim access
dim short
dim mask
dim trustee
dim aceList
dim entry
dim keys
dim key
dim i
dim pad: pad = " " & ttype

'check if a discretionary access control list (DACL) exists

If sd.ControlFlags and 4 Then

set aceList = CreateObject("System.Collections.SortedList")

'display the information from all access list entries (ACE)

For Each ace in sd.DACL

'trustee is a user or group name

trustee = ace.Trustee.Domain: if trustee <> "" then trustee =
trustee & "\"
trustee = trustee & ace.Trustee.Name

aceflags = iif(ace.AceFlags and 16,"inherited","explicit ")
aceflags = aceflags & " " & ToHex(ace.AceFlags,2)

acetype = acetypes(ace.AceType)

accessmask =
iif(summary.Exists(ace.AccessMask),summary(ace.AccessMask),"no summary")
accessmask = accessmask & " " & ToHex(ace.AccessMask,6)

entry = pad & " Trustee " & trustee _
& vbcrlf & pad & " AceFlags " & aceflags _
& vbcrlf & pad & " AceType " & acetype _
& vbcrlf & pad & " AccessMask " & accessmask

'report full details if verbose requested or if simple summary not
possible

if verbose then
for each mask in rights.Keys
if mask and ace.AccessMask then
entry = entry & vbcrlf & pad & " " &
rights(mask)
end if
next
end if

acelist.Add trustee,entry

Next

for i = 0 to acelist.Count - 1
wscript.echo vbcrlf & aceList.GetByIndex(i)
next

acelist.Clear

End If

End Function

Function ToHex ( num , numdig )
ToHex = "(0x" & Right("0000000000000000" & hex(num),numdig) & ")"
End Function

Function iif ( condition , truevalue , falsevalue )
if condition then
iif = truevalue
else
iif = falsevalue
end if
End Function