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

Last Updated on April 18, 2021 by admin

Suppose you have a shared folder for your student assignment submission in a university. You ask your students to submit their assignments to the shared folder not later than 12 midnight (Hard restriction). You can write a PowerShell script and schedule it using windows task scheduler. The script will automatically run and revoke write permission and no one will be able to paste their assignments in the shared folder after the deadline.

I am assuming a folder (Let's call it Programming Fundamentals) is created on your C drive and it is already shared for submission using the GUI or a script.

Writing the PowerShell Script

1. Paste the following code in your notepad and save it with .ps1 file extension

$Acl = Get-Acl "C:\Programming Fundamentals"
$Ar = New-Object"yourdomain\authenticated users","Write","Deny")
Set-Acl "C:\Programming Fundamentals" $Acl

Scheduling the Script

1. Open a windows task scheduler.

2. Create a task,  schedule it to run at 12 AM.

Windows Task Scheduler

3. Point the path to your PowerShell script file (Add arguments (optional) text field) and that's it.

Script executed by Scheduler

Leave a Comment