Advice on script for shares / permissions

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
mirrormirror
Posts: 129
Joined: 08 Feb 2016 20:25

Advice on script for shares / permissions

#1 Post by mirrormirror » 12 Feb 2016 03:26

Hello all. I need to migrate to a new sysytem and recreate some shares/premissions. I would like to script this process so that it is less error-prone. The OS is win7.

Here is my scenario. I have a user/system martix. Very simple - just one user per system. The names do not necessarily correspond to the numbering system (i.e user3 may have systemXYZ).

user1 / passworda / system1
user2 / passwordb / system2
user3 / passwordc / system3

I would like to:
1. script the creation of each user with correspondig password
2. create two folders per system like this:

folder\
. \[system-1]_share.ro
. \[system-1]_share.rw

. \[system-2]_share.ro
. \[system-2]_share.rw

3. share each folder
4. grant each corresponding user read-only / Full control to the applicable folder
5. Grant administrators group full control to each folder
6. add each user to a couple of common security groups

Creating the folder structure is not an issue but I don't have a great deal with scripting permissions / shares. So I am looking for advice and/or examples of how others have done this.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Advice on script for shares / permissions

#2 Post by foxidrive » 12 Feb 2016 06:45

I'm not sure if you intend creating new user accounts within Windows 7, or the shares.
sleepy...

Scripting the creation of a share with read permissions can be done like this (untested)

Code: Select all

net share mysharenameA="c:\folder\in\some\location" /grant:username1,read


net share /? shows the options.

mirrormirror
Posts: 129
Joined: 08 Feb 2016 20:25

Re: Advice on script for shares / permissions

#3 Post by mirrormirror » 12 Feb 2016 16:12

I need to create: users, folders, then share the folders

I was also looking at the icacls command - seems like there is overlapping functionality with the NET command.

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Advice on script for shares / permissions

#4 Post by Squashman » 12 Feb 2016 16:24

There are file/folder permissions and there are share permissions.

mirrormirror
Posts: 129
Joined: 08 Feb 2016 20:25

Re: Advice on script for shares / permissions

#5 Post by mirrormirror » 12 Feb 2016 17:18

There are file/folder permissions and there are share permissions.


Thanks for the reminder :). The last time I created a bunch of shares I has some access issues - verified/re-verified the share permissions with no luck. I finally had to grant file permissions on the folder for "everyone" to fix the problem.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Advice on script for shares / permissions

#6 Post by foxidrive » 12 Feb 2016 22:00

mirrormirror wrote: I finally had to grant file permissions on the folder for "everyone" to fix the problem.


That's what I do here as it's the easy way out, but is only suitable in a home environment where security isn't something you need.

The secure way to to grant the users themselves permissions to the folder and files, and not use 'everyone'.

I see that the net command can create users and there is an example here: http://www.windows-commandline.com/add- ... mand-line/

Post Reply