How to Automatically Revoke Write Permission from a Shared Folder in Windows Server 2012 R2

How to Automatically Revoke Write Permission from a Shared Folder in Windows Server 2012 R2

If you need to revoke write permission from some shared folder after a certain time, you can easily do it by writing a PowerShell script and scheduling it. For the scheduling the task you need to use Windows Task Scheduler. So you can automatically revoke write permission from a shared folder. Here we will see how we achieve the same in Windows Server 2012 R2.

Let us say the folder is named as Estimates and it is located in the C: drive.

How to Automatically Revoke Write Permission from a Shared Folder in Windows Server 2012 R2

PowerShell Script

  1. Open notepad.
  2. Then copy the code below and paste it in the notepad.
    $Acl = Get-Acl "C:\Estimates"
    $Ar = New-Object system.security.accesscontrol.filesystemaccessrule("yourdomain\authenticated users","Write","Deny")
    $Acl.SetAccessRule($Ar)
    Set-Acl "C:\Programming Fundamentals" $Acl
  3. Save it as some_file_name.ps1, note the file extension.

Schedule the Script Using Windows Task Scheduler

  1. Click on Start.
  2. Search for Task Scheduler.
  3. Click on it.
  4. When the Task Scheduler opens, create a new folder.
  5. Name it as per your needs.
  6. Then create a task and schedule it at the time you wish to revoke the write permission from the shared folder.
  7. In the Actions tab, in the Program/script textbox, enter powershell.exe and in the Add arguments textbox, add location of the file (for instance, C:\Estimates_Change.ps1).
  8. Click ok and that’s all you need to do.