TLDR Summary:

This guide provides a step-by-step PowerShell solution for Windows 11 administrators to forcefully delete folders that are otherwise inaccessible due to permission restrictions. It involves taking ownership of the folder, granting full control to the administrator, and then deleting it.

This method is particularly useful when encountering errors like “You require permission from S-1-5-21-xxxx to make changes to this folder.”

Navigating file permissions in Windows 11 can sometimes be a challenging task, especially when trying to delete a folder that denies access. This guide walks administrators through a PowerShell method to bypass these restrictions and delete such folders. It’s particularly helpful when encountering the error “You require permission from S-1-5-21-xxxx to make changes to this folder.”

Opening PowerShell as Administrator:
Start by launching PowerShell with administrative rights. This is crucial for the commands to work, as they require elevated privileges. You can do this by searching for PowerShell in the Start Menu, right-clicking on it, and selecting “Run as administrator”.

Taking Ownership of the Folder:
The first command involves taking ownership of the folder. This is necessary because, without ownership, you cannot change the folder’s permissions. The command takeown is used for this purpose, and it should be executed as follows, replacing Path\To\Folder with the actual path of your folder:

takeown /f "Path\To\Folder" /r /d y

Granting Full Control to the Administrator:
After taking ownership, the next step is to modify the folder’s permissions to grant yourself full control. This step is done using the icacls command. Replace Path\To\Folder with your folder’s path:
icacls "Path\To\Folder" /grant Administrators:F /t
Here, /grant specifies the operation, Administrators:F gives full control to the Administrators group, and /t applies these changes to all items in the folder recursively.

Deleting the Folder Verbosely:
With ownership and permissions set, you can now delete the folder. For this, use the Remove-Item cmdlet in PowerShell with the -Verbose flag for detailed output. The command should be like this:

Remove-Item -Path "Path\To\Folder" -Recurse -Force -Verbose

Script for Automation

For convenience, here’s a script that automates the above steps. Just set the $folderPath variable to the desired folder path:

$folderPath = "Path\To\Folder"  # Replace with your folder path

# Taking ownership
takeown /f $folderPath /r /d y

# Granting full control
icacls $folderPath /grant Administrators:F /t

# Deleting the folder verbosely
Remove-Item -Path $folderPath -Recurse -Force -Verbose

This PowerShell method offers a reliable solution for administrators to handle permission-restricted folders in Windows 11. It’s a valuable tool for system management and troubleshooting, ensuring smooth operation and maintenance.