I was struggling  to find share permission for
couple of servers.  After a long search I
found a script to fetch the Share permission. It is modified to get the remote
server share permission and I have included a decent error handling to it.
On Error Resume Next
Const ForReading = 1
Const ForWriting = 2
Dim strComputer
Dim objWMIService
Dim colItems
Dim objItem, intRtn,
wmiSecurityDescriptor
Dim colDACLs, objACE,
objUserGroup, strPermission 
Set objFSO =
CreateObject("Scripting.FileSystemObject")
Set objFile =
objFSO.OpenTextFile("server.txt", ForReading)
Set objFile1 =
objFSO.CreateTextFile("Share.csv", ForWriting)
Set objFile2 =
objFSO.CreateTextFile("Share_Error.csv", ForWriting)
objFile1.write
"computername,sharename,User/Group,Permission"
objFile1.WriteLine 
objFile2.write
"computername,Error Number,Description"
objFile2.WriteLine
Do Until objFile.AtEndOfStream 
strComputer =
objFile.ReadLine
Set objWMIService =
GetObject("winmgmts:\\" & _
     
                     
 strComputer & "\root\cimv2")
if  Err.Number = 0
 then                  
         
Set colItems =
objWMIService.ExecQuery("SELECT * FROM
Win32_LogicalShareSecuritySetting")
     For
Each objItem In colItems
     
   intRtn = objItem.GetSecurityDescriptor(wmiSecurityDescriptor)
     
   colDACLs = wmiSecurityDescriptor.DACL
     
   For Each objACE In colDACLs
     
       Set objUserGroup = objACE.Trustee
     
       Select Case objACE.AccessMask
     
           Case 1179817 strPermission =
"READ"
     
           Case 1245631 strPermission =
"CHANGE"
     
           Case 2032127 strPermission =
"FULL CONTROL"
     
       End Select
     
      objFile1.write strComputer & "," &
objItem.Name & "," & UCase(objUserGroup.Name) &
","  & strPermission 
 
 objFile1.WriteLine 
     
   Next
     Next
Err.Clear
Else
objFile2.write
strComputer & "," & Err.Number & "," &
Err.Description
objFile2.WriteLine 
Err.Clear
End If
loop
objFile1.close
objFile2.close
objFSO.close
 
No comments:
Post a Comment