ujala Posted December 5, 2022 Posted December 5, 2022 i have a folder of 100 users and have to give separate permissions to each user.is there any script to use and grant individual permissions to users all in a go any help will be greatly appreciated
chaplic Posted December 6, 2022 Posted December 6, 2022 Should be a group and I assume you mean a file share, but off the top of my head is a solution below Create a file called userstoperm.csv first lne is Username and below that the users, this would give Write access $peeps=import-csv UsersToPerm.csvforeach ($person in $peeps){ cacls /G $($person.username):W }
BlueScreen Posted December 6, 2022 Posted December 6, 2022 Here's a PowerShell script to go through the folders in a folder and update the permissions. This script assumes the folders have the same name as the AD user. Import-Module ActiveDirectory $FolderPath = "\\Replace-With-Path\To\Container\Folder\" foreach ($Folder in (Get-ChildItem -Path $FolderPath -Directory )) { try { $User = Get-ADUser -Identity $($Folder.Name) $User_SID = New-Object System.Security.Principal.SecurityIdentifier $User.SID #get the folder's current Access Control List $acl = Get-Acl $Folder $aces = $acl.Access #remove permissions which aren't inherited foreach ($ace in $aces) { if ($ace.IsInherited -eq $FALSE) { $acl.RemoveAccessRule($ace) } } # See this page for a full list of access controls # https://learn.microsoft.com/en-us/dotnet/api/system.security.accesscontrol.filesystemrights?view=net-7.0 # see this page for inheritance flags # https://learn.microsoft.com/en-us/dotnet/api/system.security.accesscontrol.inheritanceflags?view=net-7.0 # see this page for Propogation flags # https://learn.microsoft.com/en-us/dotnet/api/system.security.accesscontrol.propagationflags?view=net-7.0 # add read access to the folder and files # Replace "ReadAndExecute" with "Modify" to allow the user to create files and folders in this one. $User_Perms = $User_SID,"ReadAndExecute","ObjectInherit,ContainerInherit", "none", "Allow" $User_ACE = New-Object System.Security.AccessControl.FileSystemAccessRule $User_Perms $acl.AddAccessRule($User_ACE) #add full control to sub folders and files $User_Perms = $User_SID,"FullControl","ObjectInherit,ContainerInherit", "InheritOnly", "Allow" $User_ACE = New-Object System.Security.AccessControl.FileSystemAccessRule $User_Perms $acl.AddAccessRule($User_ACE) #write permissions back to the folder Set-ACL -Path $Folder -AclObject $acl } catch { write-warning "Issues with $($Folder.Name)" } } As always test before deploying in anger. 1
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now