Created
April 13, 2025 07:33
-
-
Save DraconicDragon/43739c634251bf212ca553c5c905937c to your computer and use it in GitHub Desktop.
Im stupid so i had chatgpt make this script, i dont actually know if its doing anything but i hope so
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Define path | |
| $downloadsPath = "$env:USERPROFILE\Downloads" | |
| $user = "$env:USERNAME" | |
| $identity = "$env:USERDOMAIN\$user" | |
| # Get current ACL | |
| $acl = Get-Acl $downloadsPath | |
| # Remove all existing rules to start clean | |
| $acl.Access | ForEach-Object { $acl.RemoveAccessRule($_) } | |
| # 1. Deny deletion of the Downloads folder itself (not inherited by contents) | |
| $denyDeleteSelf = New-Object System.Security.AccessControl.FileSystemAccessRule( | |
| "Everyone", | |
| "Delete", | |
| "None", # Applies to folder only | |
| "None", | |
| "Deny" | |
| ) | |
| $acl.AddAccessRule($denyDeleteSelf) | |
| # 2. Allow everyone normal access to contents | |
| $allowContents = New-Object System.Security.AccessControl.FileSystemAccessRule( | |
| "Everyone", | |
| "Read, Write, Modify, DeleteSubdirectoriesAndFiles", | |
| "ContainerInherit,ObjectInherit", # Applies to subfolders and files | |
| "None", | |
| "Allow" | |
| ) | |
| $acl.AddAccessRule($allowContents) | |
| # 3. Grant full control to current user | |
| $allowFull = New-Object System.Security.AccessControl.FileSystemAccessRule( | |
| $identity, | |
| "FullControl", | |
| "ContainerInherit,ObjectInherit", | |
| "None", | |
| "Allow" | |
| ) | |
| $acl.AddAccessRule($allowFull) | |
| # Apply permissions | |
| Set-Acl -Path $downloadsPath -AclObject $acl | |
| Write-Output "Permissions reset: Folder protected, contents editable." | |
| # Set ownership to current user | |
| takeown /F $downloadsPath /R /D Y | Out-Null | |
| icacls $downloadsPath /setowner "$identity" /T | Out-Null | |
| Write-Output "Ownership reset to $identity." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment