PowerShell v3 Managing Share/NTFS Permissions -


background:

i've been trying write powershell script add/remove permissions folder. script 5th script in sequence of scripts kick off after another. scripts have shared variables, etc.

scripts follows:

  1. create ad group object
  2. create ad user object (or two, three, four, etc.)
  3. create user folder on application server , create data folder (to shared associated users) on file server
  4. this script, change permissions supposed be

i'm trying following (ntfs):

  1. user folder - system (full), administrator (full), domain admin (full), ad group (modify), users (modify)
  2. data folder - system (full), administrator (full), domain admin (full), ad group (modify), network service (full), users (read)

i'm trying following (share):

  1. data folder - system (full), administrator (full), domain admin (full), ad group (modify)

here i've been trying work with:

if use method locally, works great. shares folder such "c:test" without issue. can't run against servers (not sure if it's because i'm using variables or what). in case, data folder i'm trying change permissions on.

# configures folders have necessary permissions  # set folder path  # gname, sharedcomputername, , clientname come values in previous script  $server = $sharecomputername $share = "\d$\tran\"+$clientname  $fullsharepath = "$server"+"$share"  # assign permissions  net share $gname=$fullsharepath '/grant:administrators,full' '/grant:domain\account,change' 

server os 2008 r2 , powershell v3. dc/ad 2012 though.


edit 4/2/15 - not duplicate question (i guess marked such)...see response user below.


edit 4/6/15 - how accomplished looking do...

here ended doing, pointer (to other threads/sources) rich chiavaroli.

to handle ntfs permissions, did following:

# setting ntfs directory permissions  $acl = get-acl "\\$servername\folderpath"  $rule = new-object system.security.accesscontrol.filesystemaccessrule("domain\user or usergroup","modify", "containerinherit, objectinherit", "none", "allow") $acl.addaccessrule($rule)  $rule = new-object system.security.accesscontrol.filesystemaccessrule("users","modify", "containerinherit, objectinherit", "none", "allow") $acl.addaccessrule($rule)  set-acl "\\$servername\folderpath" $acl 

to handle share permissions, did following:

# configures folders have necessary permissions  # set folder path  $server = enter server name here (ex: \\test) $share = enter path folder here (ex: c:\test)  # assign share permissions  # user name/group give permissions $trustee = ([wmiclass]'win32_trustee').psbase.createinstance() $trustee.domain = "corp" $trustee.name = "$gname"  $trustee2 = ([wmiclass]'win32_trustee').psbase.createinstance() $trustee2.domain = "domain" $trustee2.name = "domain admins"  # access mask values $fullcontrol = 2032127 $change = 1245631 $read = 1179785  # create access-list $ace = ([wmiclass]'win32_ace').psbase.createinstance() $ace.accessmask = $fullcontrol $ace.aceflags = 3 $ace.acetype = 0 $ace.trustee = $trustee  $ace2 = ([wmiclass]'win32_ace').psbase.createinstance() $ace2.accessmask = $fullcontrol $ace2.aceflags = 3 $ace2.acetype = 0 $ace2.trustee = $trustee2  # security descriptor containing access $sd = ([wmiclass]'win32_securitydescriptor').psbase.createinstance() $sd.controlflags = 4 $sd.dacl = $ace, $ace2 $sd.group = $trustee $sd.owner = $trustee  $share = get-wmiobject win32_share -list -computername "$server" $share.create("$share", "name of share", 0, 100, "", "", $sd) 

Comments

Popular posts from this blog

How to run C# code using mono without Xamarin in Android? -

c# - SharpSsh Command Execution -

python - Specify path of savefig with pylab or matplotlib -