I’m facing a problem at my workplace which I’m unable to resolve on my own. We have a shared folder where all employees can create files. However, we need to configure the folder so that all newly created files, including those in subfolders, become read-only after each day. The folder is hosted on a Windows 10-based machine.

I’ve found a basic Powershell script that can make all files in a folder read-only:

$folderPath = 'C:\TestFolder' 
Get-ChildItem -Path $folderPath -Recurse -File | % { $_.IsReadOnly=$True }`

The Powershell script is executed from an admin account, resulting in only the admin being able to modify the files in the shared folder. This also means that users are unable to edit any files once the script is run each day. The cycle repeats every day, with new files created by users being automatically set to read-only on the following day.

I’m seeking suggestions on how to implement these file permissions using Powershell.

Here’s the algorithm I’ve devised for the script:

  • Locate all files in a recursive manner.
  • Set them to read-only.
  • Remove user access to modify any file found.
  • Ensure that users still have access to create new files and view existing ones.

Any suggestions or recommendations on how to improve this algorithm are greatly appreciated!

Askify Moderator Edited question May 1, 2023