Need configure Script PowerShell to modify NTFS permissions on folders and subfolders

The Gentelman 1 Reputation point
2020-09-30T11:54:25.067+00:00

Hello Team,
We have a domain controller Win Serv2019 Std using to share 3 principal folders and subfolders like this structure :
Folder1 : 1000-2599
Folder2 : 2600-3000
Folder3 : 3000-5000
Each principal folder contains a 100 folders with the same structure:
1000-2599\ 04_1000_Name1
\ 04_1001_Name2
.... 04_1100_Name100
Each subfolder 04_xxxx_Namexxx contains 4 subfolders:
1000-2599\04_1000_Name1\ admin
\ Project review
\contact
\Technique
So we need to create a Powershell script to allow AllUsers and TechUsers securityGroups to acces only to Technique subfolder for each folder with modify access right (R+W+M).
The 2 groups should not have access to the 3 others subfolders : Project review, admin, and contact.
In Total we have 300 folders with the same structure 04_xxxx_Namexxx.
Could you please help us to modify this using a script ?
thanks a lot!
Regards,

Windows Server
Windows Server
A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.
12,208 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,390 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Ian Xue (Shanghai Wicresoft Co., Ltd.) 30,386 Reputation points Microsoft Vendor
    2020-10-01T10:05:51.93+00:00

    Hi,

    You could use Set-Acl to set the permissions, like

    $path = "C:\folder"  
    $acl = Get-Acl $path  
    $AccessRule = New-Object System.Security.AccessControl.FileSystemAccessRule("YourUsers","Modify", "ContainerInherit,ObjectInherit", "None", "Allow")  
    $acl.SetAccessRule($AccessRule)  
    $acl | Set-Acl $path  
    

    For more information
    https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.security/set-acl?view=powershell-7

    Best Regards,
    Ian

    ============================================

    If the Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

  2. TimCerling(ret) 1,156 Reputation points
    2020-09-30T12:39:40.377+00:00

    Q&A is a location to help provide Answers for Questions submitted. It is not a consulting organization for writing scripts.

    https://gallery.technet.microsoft.com/scriptcenter is a repository of thousands of user submitted scripts. It may not contain a script that does exactly what you want to do, but it most likely contains a script or two that you can use as an example to modify to fit your needs. If you have questions about how something works in the script, the windows-server-powershell tag will direct you to experts in Windows PowerShell who can assist you in your understanding.

    If you want somebody to write a script for you, there are freelancer sites on the web. Search the web to find someone whom you can hire to write a script for you.

    0 comments No comments