How to take ownership of a terminal user folder so you can safely remove it

Intro

This was an annoying issue for me to remove the a terminal server user's profile from our file servers.

Each time you need to remove an user's folder you get the standard access denied, then you need to change the permissions, inheritance, etc... so to save my colleagues and myself the trouble of repeating these steps, I've created a simple script in which you only need to enter the username folder and presto, the permissions are now your to delete.

I could remove it through the script as well, but its safer to do it manually as it works as a double check. Perhaps future wise it will be extended to do this with additional verifications.

Article

The script itself has some minor checks in place to make sure you enter the correct username as this will remove ALL permissions of the original user and assign them to yours!

The commandlet below takes the actual ownership and changes the inheritance:

takeown /f $path\$username /r /d y

icacls $path\$username /q /c /t /reset

 

To change the path, simple change the VAR $path to your TS profiles folder location.
e.g $path = D:\TS\Profiles\

Document

Preview not available.

Document options

Download

Gallery


Comments

Loading Comments...