'LISTSHARES.VBS 'Version 2.1 'Last Modified July 2004 'Jeffery Hicks 'jhicks@jdhitsolutions.com 'http://www.jdhitsolutions.com 'Summary: List all shares for a specified server 'Usage: cscript //nologo listshares.vbs servername 'Notes: Enumerate all shares as well as getting NTFS permissions for the root 'of each share. Logs output to servername-S.txt. If the file already exists, it 'will be overwritten. 'Script maps Z: to each share and then executes CACLS in order to capture 'NTFS permissions. Any existing connections to Z: will be removed. 'This works for all shares, visible and hidden, but it won't display 'admin shares such as C$. 'It is STRONGLY recommended to run this from a command prompt using cscript. 'If you want to do a list of computers, create a text list of computers: 'server01 'server02 'server03 'At a prompt run the following command from the same directory as this script: 'for /f %i in (servers.txt) do @cscript listshares.vbs %i ' License :: ' Copyright 2004 JDH Information Technology Solutions, Inc. ' This program is free software; you can redistribute it and/or modify ' it under the terms of the GNU General Public License as published by ' the Free Software Foundation; either version 2 of the License, or ' (at your option) any later version. ' This program is distributed in the hope that it will be useful, ' but WITHOUT ANY WARRANTY; without even the implied warranty of ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ' GNU General Public License for more details at HTTP://www.gnu.org/licenses/gpl.txt ' ********************************************************************************* ' * DO NOT USE IN A PRODUCTION ENVIRONMENT UNTIL YOU HAVE TESTED IN A SECURED LAB * ' * ENVIRONMENT. USE AT YOUR OWN RISK. * ' ********************************************************************************* On Error Resume Next dim strSrv, objShare dim wshNetwork, wshell dim fso, f dim objExec iCounter=0 if Wscript.Arguments.Count <1 then wscript.echo VBCRLF& "OOPS! You failed to specify a server." & VBCRLF ShowUsage Wscript.quit end if if Wscript.Arguments.Count >0 then if Wscript.Arguments(0)="/?" then wscript.echo VBCRLF ShowUsage wscript.quit end if strSrv=Wscript.Arguments(0) end if 'name of log file. Default is computername-shares.txt strLog=strSrv& "-Shares.txt" Set wshell=Wscript.Createobject("Wscript.Shell") Set WshNetwork = WScript.CreateObject("WScript.Network") Set fso=CreateObject("Scripting.FileSystemObject") Set f=fso.CreateTextFile(strLog) f.Writeline "Checking Server " & strSrv & " for Shares - " & NOW & vbcrlf wscript.echo "Checking Server " & strSrv & " for Shares." set objShare= GetOBJect("WinNT://" & strSrv &"/lanmanserver") If err.number<>0 then f.WriteLine "Error #"&err.number& ": " & err.description f.WriteLine "There was a problem connecting to " &strSrv Else WScript.echo "Server Name = " & strSrv For Each share in objShare iCounter=iCounter+1 WScript.echo "Examining " & share.name f.WriteLine "Share Name = " & share.name f.WriteLine " Share Path = " & share.path f.WriteLine " Description = " & share.description MapIt strSrv,share.name Next f.WriteBlankLines(2) f.WriteLine "Enumerated " & iCounter & " shares." End If f.Close wscript.Echo "See " & strLog & " for results of share audit." set f=Nothing set fso=Nothing set strSrv=Nothing set objShare=Nothing set wshShell=Nothing set wshNetwork=Nothing wscript.quit '////////////////////////// '/ Map & Check / '////////////////////////// 'Map Drive Sub MapIt(server,share) On Error Resume Next 'uncomment for debugging 'wscript.echo "mapping " & "\\"&server&"\"&share 'remove any existing mappings to Z: wshNetwork.RemoveNetworkDrive "Z:" WshNetwork.MapNetworkDrive "Z:", "\\"&server&"\"&share set objExec=wShell.Exec("cacls Z:\") do while objExec.StdOut.AtEndOfStream <>True f.WriteLine objExec.StdOut.Readline WScript.Sleep 100 Loop wshNetwork.RemoveNetworkDrive "Z:" End Sub '////////////////////////// '/ Show Usage / '////////////////////////// Function ShowUsage wscript.echo "Usage: " & Wscript.ScriptName wscript.echo "Cscript listshares.vbs [servername]" wscript.echo " Example: cscript listshares.vbs filesrv01" & VBCRLF wscript.echo "Cscript listshares.vbs /? will display this help message" End Function