set permission based on folder name input

Hello,

Im newbie for scripting or powershell

Case background

We have created 120 folder in //fileserver/sharepath/ and all this 120 folder been name using users AD username.

How can i automated the permission setting for each folder (full control), using the folder name input.

Example

user = John Smith and the AD username jsmith

//fileserver/sharepath/jsmith  

permission setting for above folder should be full control for the admin and jsmith account only

Thanks

  

October 29th, 2013 2:27am

This console command will do the trick:

for /d %a in (*.*) do @icacls "%a"  /T  /grant "%a":F  System:F  Administrator:F

Best to first test the command on a single folder:

icacls "jsmith"  /T  /grant "jsmith":F  System:F  Administrator:F


Free Windows Admin Tool Kit Click here and download it now
October 29th, 2013 3:04am

You can try this with the below code. Please test with one or two folder in different location before applying in PRODUCTION.

cls
Set-Location "//fileserver/sharepath/"
$SharedFolder= "//fileserver/sharepath/"
$Folders = Import-Csv "c:\FolderPermission.csv"
<#
The FolderPermission.csv format shuld be like below
Name,User,Perm,Rule
Dir1,AduserName1,FullControl,Allow
Dir2,AdUserName2,FullControl,Allow
Dir3,AdUserName3FullControl,Allow
#>
ForEach ($Folder in $Folders) {
$Dir = $Folder.Name
$User = $Folder.User
$Perm = $Folder.Perm
$Rule = $Folder.Rule
$ACL = Get-Acl "$Pfad\$Dir"
$ACL.AddAccessRule((New-Object System.Security.AccessControl.FileSystemAccessRule("$User", "$Perm", "ContainerInherit, ObjectInherit", "None", "$Rule")))
Set-Acl "$SharedFolder\$dir" $Acl
}
October 29th, 2013 4:00am

This console command will do the trick:

for /d %a in (*.*) do @icacls "%a"  /T  /grant "%a":F  System:F  Administrator:F

Best to first test the command on a single folder:

icacls "jsmith"  /T  /grant "jsmith":F  System:F  Administrator:F


Free Windows Admin Tool Kit Click here and download it now
October 29th, 2013 9:58am

You can try this with the below code. Please test with one or two folder in different location before applying in PRODUCTION.

cls
Set-Location "//fileserver/sharepath/"
$SharedFolder= "//fileserver/sharepath/"
$Folders = Import-Csv "c:\FolderPermission.csv"
<#
The FolderPermission.csv format shuld be like below
Name,User,Perm,Rule
Dir1,AduserName1,FullControl,Allow
Dir2,AdUserName2,FullControl,Allow
Dir3,AdUserName3FullControl,Allow
#>
ForEach ($Folder in $Folders) {
$Dir = $Folder.Name
$User = $Folder.User
$Perm = $Folder.Perm
$Rule = $Folder.Rule
$ACL = Get-Acl "$SharedFlder\$Dir"
$ACL.AddAccessRule((New-Object System.Security.AccessControl.FileSystemAccessRule("$User", "$Perm", "ContainerInherit, ObjectInherit", "None", "$Rule")))
Set-Acl "$SharedFolder\$dir" $Acl
}
October 29th, 2013 10:54am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics