Take Ownership KB ID 0001200
Problem
I had a bunch of old user profile folders I needed to delete today, When setup properly even the domain administrator can’t get in there and delete them;
You need permission to perform this action.
You don’t currently have persmission to access this folder
If it’s just one folder then simply take ownership, grant yourself rights and delete it! But I had a lot of folders so I needed a more robust (read less work) solution.
Solution: Take Ownership
Take Ownership of all Folders/Sub-Folders, and Files
Open an administrative command window, and execute the following command;
takeown /a /r /d Y /f C:\"Path-To-Folder"
Grant ‘Full Control’ Rights to all Folders/Sub-Folders, and Files
Just because you are the owner, that does not mean you have any rights to the folders and files, to grant full control to the administrators group.
icacls C:\"Path-To-Folder" /grant administrators:F /t
You can then delete the folder and its contents recursively with the following command.
Remove-Item -Path "Path-To-Folder" -Force -Recurse
Related Articles, References, Credits, or External Links
Can’t Delete a File or Folder or Take Ownership
24/04/2018
Hello Pete,
Appreciate the help from your website but, here’s the thing.
Some very bad russians managed to dump something on our server in the sysroot\sys32 folder and even tho your solution will grant full perms for everything, it will not release this one file. If you have any thoughts on this, they would be gladly received.
tia if you do.
Gary
24/04/2018
IF=f it’s immovable boot with a Linux DVD and mount the partition – then you will be able to delete it, or try MoveOnBoot
Pete
07/02/2020
… How do you know they were Russian? Sounds a little racist to me.
07/02/2020
Unless the files were in Russian? 🙂
30/12/2020
Thanks for this tip. I had a very large music directory with a lot of unique file which I couldn’t play because the where blocked in one way or another. It took me more than a week to find out that this solution of your worked. Even a lot of unlock software solutions didn’t work, stopping the share option, copying the whole drive and use it on another pc’s, deleting or changing administrator rights. It was a hell to come up with the right solution. Thanks again. You saved my live. 😉
01/01/2021
Glad to help Peter 🙂
03/03/2021
What is a good web page or site to learn how to use icacls ? (besides Microsoft)
Thank you