Hi all,
I created this script which publishes a shared folder in AD, then creates the shared folder, then assigns the shared folder to a group. My question now is how do I go about setting permissions for this shared folder? I have seen some post regarding WMI and other ways of doing it but which is the easiest for a beginner.
Thanks.
I created this script which publishes a shared folder in AD, then creates the shared folder, then assigns the shared folder to a group. My question now is how do I go about setting permissions for this shared folder? I have seen some post regarding WMI and other ways of doing it but which is the easiest for a beginner.
Thanks.
Code:
' Input File: sharedlist.csv
'
' Parameters: organizationalunit,sharename,description,group
Dim objFSO, objTextfile, ou_arr, s
Const ForReading = 1
Const FILE_SHARE = 0
Const AllowMaximum = True
Const ADS_PROPERTY_APPEND = 3
strComputer = "."
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextfile = objFSO.OpenTextFile("shareslist.csv", ForReading)
Do while objTextfile.AtEndOfStream <> True
s = objTextfile.Readline
If instr(s, ",") Then
ou_arr = split(s, ",")
wscript.Echo "ou = " & ou_arr(0)
wscript.Echo "sharename = " & ou_arr(1)
Wscript.Echo "description = " & ou_arr(2)
Wscript.Echo "group = " & ou_arr(3)
' Publish Shared Folder in Active Directory
Set objComputer = GetObject ("LDAP://OU=" & ou_arr(0) & ", DC=test")
Set objShare = objComputer.Create("volume", "CN=" & ou_arr(1) )
objShare.Put "uNCName", "\\2003srv\" & ou_arr(1)
objShare.Put "Description", "" & ou_arr(2)
objShare.SetInfo
Wscript.Echo " Published in AD."
WScript.Echo VbCrLf
'Make share
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set objNewShare = objWMIService.Get("Win32_Share")
errReturn = objNewShare.Create ("C:\Shares\" & ou_arr(1),"" & ou_arr(1), FILE_SHARE,_
AllowMaximum, "Public share for the Health group.")
Wscript.Echo errReturn
Wscript.Echo "Share created."
WScript.Echo VbCrLf
Set objGroup = GetObject("LDAP://cn=" & ou_arr(3) & ",ou=" & ou_arr(0) & ",dc=test")
objGroup.PutEx ADS_PROPERTY_APPEND, "member", Array("cn=" & ou_arr(1) & ",ou=" & ou_arr(0) & ",dc=test")
objGroup.SetInfo
If Err <> 0 Then
Wscript.echo Err.Number & " -- " & Err.Description
Err.Clear
End If
Else
Wscript.Echo "End of file"
End If
Loop
objTextFile.Close