Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 KB | None | 0 0
  1. # Configures the folders to have necessary permissions
  2.  
  3. # Set the folder path
  4.  
  5. # gname, sharedcomputername, and clientname all come from values in previous script
  6.  
  7. $Server = $ShareComputerName
  8. $Share = "d$Tran"+$ClientName
  9. $FullSharePath = "$Server"+"$Share"
  10.  
  11. # Assign the permissions
  12.  
  13. net share $gname=$FullSharePath '/Grant:Administrators,FULL' '/Grant:DomainAccount,CHANGE'
  14.  
  15. # Setting NTFS directory permissions
  16.  
  17. $acl = Get-Acl "\$servernamefolderpath"
  18.  
  19. $rule = New-Object System.Security.AccessControl.FileSystemAccessRule("domainuser or usergroup","Modify", "ContainerInherit, ObjectInherit", "None", "Allow")
  20. $acl.AddAccessRule($rule)
  21.  
  22. $rule = New-Object System.Security.AccessControl.FileSystemAccessRule("Users","Modify", "ContainerInherit, ObjectInherit", "None", "Allow")
  23. $acl.AddAccessRule($rule)
  24.  
  25. Set-Acl "\$servernamefolderpath" $acl
  26.  
  27. # Configures the folders to have necessary permissions
  28.  
  29. # Set the folder path
  30.  
  31. $Server = Enter your server name here (ex: \test)
  32. $Share = Enter the path to the folder here (ex: C:Test)
  33.  
  34. # Assign the Share Permissions
  35.  
  36. # User Name/Group to give permissions to
  37. $trustee = ([wmiclass]'Win32_trustee').psbase.CreateInstance()
  38. $trustee.Domain = "Corp"
  39. $trustee.Name = "$gname"
  40.  
  41. $trustee2 = ([wmiclass]'Win32_trustee').psbase.CreateInstance()
  42. $trustee2.Domain = "Domain"
  43. $trustee2.Name = "Domain Admins"
  44.  
  45. # Access mask values
  46. $fullcontrol = 2032127
  47. $change = 1245631
  48. $read = 1179785
  49.  
  50. # Create access-list
  51. $ace = ([wmiclass]'Win32_ACE').psbase.CreateInstance()
  52. $ace.AccessMask = $fullcontrol
  53. $ace.AceFlags = 3
  54. $ace.AceType = 0
  55. $ace.Trustee = $trustee
  56.  
  57. $ace2 = ([wmiclass]'Win32_ACE').psbase.CreateInstance()
  58. $ace2.AccessMask = $fullcontrol
  59. $ace2.AceFlags = 3
  60. $ace2.AceType = 0
  61. $ace2.Trustee = $trustee2
  62.  
  63. # Security descriptor containing access
  64. $sd = ([wmiclass]'Win32_SecurityDescriptor').psbase.CreateInstance()
  65. $sd.ControlFlags = 4
  66. $sd.DACL = $ace, $ace2
  67. $sd.group = $trustee
  68. $sd.owner = $trustee
  69.  
  70. $share = Get-WmiObject Win32_Share -List -ComputerName "$Server"
  71. $share.create("$Share", "Name of the share", 0, 100, "", "", $sd)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement