setShares.bat


Simply create network shares for Windows File Sharing, based on a list of paths and share names. If the path does not exists, the directory will be created first. The list is incorporated in the batch file itself, and the batch file will read itself as text file for input ...

For a discussion of the design of the file and directory system, and which shares will be used to what purpose, please refer to File Management and Group Policy : Roaming User Profiles and Folder Redirection.

@GOTO batch

Share			Path			Remark
-------------------------------------------------------------
Documents		F:\documents		data
Reports			F:\reports		Database_Reports
Home$			F:\home			user_home
Users$			F:\users		user_profiles
Sjablonen		F:\sjablonen		Office_Templates
AntiVirus		E:\AntiVirus		virus_signature_updates
Install			E:\install		software_installers
Distri			E:\distri		network_software_distribution_points
Setup			E:\setup		setup_commandlines


:batch
@echo off
REM Koen Noens
REM February 2005

FOR /F "skip=4 tokens=1,2,*" %%i in (%0)do (

	if "%%i" == "" GOTO BATCHEND

	if NOT EXIST %%j\NUL MD %%j
	net share %%i=%%j /unlimited /remark:"%%k"
)


:batchend
exit /B



		

enumerateShares.vbs

To document shares on an existing number of fileservers and possibly create a list that can be used as input in the setShares.bat script above, you can simple execute something like this (on each server) :

 net share
	

A more elaborate script, such as the following, can be used if you want to query multiple file servers and collect additional information about the share.
[Roughly based on http://www.activexperts.com/activmonitor/windowsmanagement/adminscripts/filesfolders/sharedfolders/#EnumNetworkShares.htm].

Works best with cscript and output redirection, like ' cscript enumerateShares.vbs > shares.txt '

On Error resume next

servers= array ( "fsrv01","fsrv02","fsrv03", "fsrv04" )
SEP=vbTab               'separator for output eg tab-separated for use in ms excel


for each srv in servers
        getShares srv
next


Private Sub getShares (strHostname)

        strComputer = strhostname

        Set objWMIService = GetObject("winmgmts:" _
        & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

        'Set colShares = objWMIService.ExecQuery("Select * from Win32_Share")
        Set colShares = objWMIService.ExecQuery("Select * from Win32_Share where type=0")

        For each objShare in colShares
                strUNC = "\\" & strhostname & "\" & objShare.Name
                strSize = getSharedFolderSize (strUNC)

                result = strComputer & SEP & _
                        objShare.Name & SEP & _
                        objShare.Path & SEP & _
                        strSize & SEP & _
                        objShare.Description

                wscript.echo result
        Next

       
End Sub

Private Function getSharedFolderSize (strShare)
On Error Resume Next

        Set fso = CreateObject("Scripting.FileSystemObject")
 
        Set fldr = fso.GetFolder(strShare)
        UNIT=" B"
        result = Round (fldr.Size ,2)
        
                ' scale to KB,MB,GB
                if result > 1024 Then
                        UNIT=" KB"
                        result= Round((result/1024),2)
                end If
                if result > 1024 Then
                        UNIT=" MB"
                        result= Round((result/1024),2)
                end If
                if result > 1024 Then
                        UNIT=" GB"
                        result= Round((result/1024),2)
                end If
               

        getSharedFolderSize = result & UNIT
End Function

Koen Noens
june 7, 2005