Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to create group and share directory in batch mode 1

Status
Not open for further replies.

bunwong

IS-IT--Management
Mar 15, 2004
13
HK
Dear all,

Do you know how to

- create user group
- share directory

in batch mode for windows 2003?

I have tried "Net Group" but it is only for Domain Controller. But my server is standalone, and I want to create local group.

Thanks,

Bun
 
NET LOCALGROUP and NET SHARE would probably do what you want. Use NET HELP LOCALGROUP and NET HELP SHARE for more information.
 
Requires text file listing groups, one group per line
Code:
Option Explicit

If right(lcase(wscript.fullname),11) <> "cscript.exe" Then
	MsgBox "This script must be run using cscript.exe",0,"Real administrators use the keyboard"
	WScript.Quit
End If

Dim oRootDSE, oOU, oGroup, oGroupName
Dim sOU, sGroupName, sLongGroupName, sDNSDomain

Dim oFSIn, oTSIn, oFSOut, oTSOut
Dim sInFile, sOutFile


' -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
'                             Edit to suit
' -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
sOU = "OU=HQ,OU=SR," ' Note trailing comma
sInFile = "hqGroups.txt"
sOutFile = "hqGroups.log"
' -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

Set oFSIn = CreateObject("Scripting.FilesystemObject")
Set oTSIn = oFSIn.OpenTextFile(sInFile)
Set oFSOut = CreateObject("Scripting.FilesystemObject")
Set oTSOut = oFSOut.CreateTextFile(sOutFile, True)

Set oRootDSE = GetObject("LDAP://RootDSE")
sDNSDomain = oRootDSE.Get("DefaultNamingContext")

Do Until oTSIn.AtEndOfStream
	sGroupName = trim(oTSIn.ReadLine)
	if len(sGroupName) > 0 then
		sLongGroupName = "CN=" & sGroupName
		Set oOU = GetObject("LDAP://" & sOU & sDNSDomain)
		Set oGroup = oOU.Create("Group", sLongGroupName)
		oGroup.Put "sAMAccountName", sGroupName
		oGroup.setInfo
		oTSOut.WriteLine(sGroupName & " created")
	end if
Loop

' -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
'                             Clean Up
' -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

Set oRootDSE = Nothing
Set oFSIn = Nothing
Set oFSOut = Nothing
Set oOU = Nothing
Set oGroupName = Nothing

oTSIN.Close
oTSOut.Close
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top