다음을 통해 공유


Script per la creazione di risorse share su un cluster

Di seguito il codice di uno script vbs per la creazione di risorse share su un cluster.

Const ForReading = 1
strNomeCluster = "ClusterFS"

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile _
("c:\shares.txt", ForReading)

Do Until objTextFile.AtEndOfStream

        strNextLine = objTextFile.Readline
arrShareList = Split(strNextLine , ",")
Set objShell = CreateObject("WScript.Shell")
strCommand = "cluster . res """& arrShareList(0) &""" /create /group:""" _
& strNomeCluster &""" /type:""File Share"""
'wscript.echo strCommand
Set objExec = objShell.Exec(strCommand)
strResults = LCase(objExec.StdOut.ReadAll)
Wscript.echo strResults

    strCommand = "cluster . res """& arrShareList(0) &""" /priv path=""" _
& arrShareList(1) & """"
'wscript.echo strCommand
Set objExec = objShell.Exec(strCommand)
strResults = LCase(objExec.StdOut.ReadAll)
Wscript.echo strResults

    strCommand = "cluster . res """& arrShareList(0) &""" /priv Sharename=""" _
& arrShareList(0) & """"
'wscript.echo strCommand
Set objExec = objShell.Exec(strCommand)
strResults = LCase(objExec.StdOut.ReadAll)
Wscript.echo strResults

    arrSharePerm = Split(arrShareList(2) , ";")
For Each strGroup in arrSharePerm
strCommand = "cluster . res """& arrShareList(0) &""" _
/priv security="""& strgroup &""",grant,c:security"
'wscript.echo strCommand
Set objExec = objShell.Exec(strCommand)
strResults = LCase(objExec.StdOut.ReadAll)
Wscript.echo strResults
Next

    strCommand = "cluster . res """& arrShareList(0) &""" /priv _
security=BUILTIN\Administrators,grant,f:security"
'wscript.echo strCommand
Set objExec = objShell.Exec(strCommand)
strResults = LCase(objExec.StdOut.ReadAll)
Wscript.echo strResults

    arrSharePerm = Split(arrShareList(3) , ";")
For Each strGroup in arrSharePerm
strCommand = "cluster . res """& arrShareList(0) &""" _
/priv security="""& strgroup &""",grant,r:security"
'wscript.echo strCommand
Set objExec = objShell.Exec(strCommand)
strResults = LCase(objExec.StdOut.ReadAll)
Wscript.echo strResults
Next

    strCommand = "cluster . res """& arrShareList(0) &""" _
/AddDep:""File share IP Address"""
'wscript.echo strCommand
Set objExec = objShell.Exec(strCommand)
strResults = LCase(objExec.StdOut.ReadAll)
Wscript.echo strResults

    strCommand = "cluster . res """& arrShareList(0) &""" _
/AddDep:""File share Name"""
'wscript.echo strCommand
Set objExec = objShell.Exec(strCommand)
strResults = LCase(objExec.StdOut.ReadAll)
Wscript.echo strResults

    strCommand = "cluster . res """& arrShareList(0) &""" _
/prop Description=""" & arrShareList(4) & """"
'wscript.echo strCommand
Set objExec = objShell.Exec(strCommand)
strResults = LCase(objExec.StdOut.ReadAll)
Wscript.echo strResults

    strCommand = "cluster . res """& arrShareList(0) &""" _
/priv csccache=48"
'wscript.echo strCommand
Set objExec = objShell.Exec(strCommand)
strResults = LCase(objExec.StdOut.ReadAll)
'Wscript.echo strResults

    strCommand = "cluster . res """& arrShareList(0) &""" /On"
'wscript.echo strCommand
Set objExec = objShell.Exec(strCommand)
strResults = LCase(objExec.StdOut.ReadAll)
Wscript.echo strResults

Loop

Lo script lavora in un cluster definito localmente sul server e all'interno di un cluster group che deve esistere, di nome ClusterFS. Lo scirpt prende in input il file c:\shares.txt che contiene una lista di elementi secondo il seguente formato:

<nome share>,<path>,[<gruppo con permessi R/W>;<gruppo con permessi R/W>;...],[<gruppo con permessi R>;<gruppo con permessi R>;...],<Commento>

esempio:

IT,c:\ITShare,Gestori IT;Gestori FS,Utenti IT,Share destinata ai file di IT

Inoltre lo script crea le dipendenze delle risorse share create dalle risorse denominate "File share IP Address" e "File share Name", che devono esistere nel cluster group indicato sopra, e disattiva la modalità cache come consigliato per le risorse di tipo file share.

smile_regular