2

I'm trying to delete unused user profiles off a terminal services server to gain some free space. However, I can't seem to find a way to delete the AppData folder as I keep getting "Access Denied" errors. I was wondering if anyone had a technique around this issue?

$removefolder = [System.IO.Path]::GetFullPath("\\server1\c$\users\" + $folder.name)
Remove-Item $removefolder -recurse -force

Remove-Item : Access to the path '\server1\c$\users\user1\AppData\Local\Application Data' is denied.

seva titov
  • 11,720
  • 2
  • 35
  • 54
  • Use an account that has access...? Take ownership of the directory first? – arco444 Jan 27 '15 at 16:48
  • 1
    look for the owner / permissions – Lucas Bertollo Jan 27 '15 at 16:49
  • arco444, I'm running the script as Administrator with an Account that is a Domain admin, so its unlikely there is anything else that I could use. – Thomas Guidry Jan 27 '15 at 16:51
  • Ownership could be an issue but are any of those files it is complaining about open in the system? – Matt Jan 27 '15 at 16:56
  • Matt, I can't even access that path in the GUI even when I set the owner to Administrator of the server and proped perms down. Its not an open file either as I can manually delete profiles all day long. – Thomas Guidry Jan 27 '15 at 16:58
  • If you're using windows 7 or later, your attempt is going to fail. The computer will create a temporary login the next time the person logs in. The proper way to delete a user profile is to use System Properties. Deleting a profile there removes the registry data and all user folders. – Colyn1337 Jan 27 '15 at 17:33
  • Well my attempt is failing for completely different reasons. The script will remove the registry entries as well as the profile folder *if* I could figure out a way around the access issue. I'm also not worried about temp log ins considering that the users I want to remove no longer work for the company. While using System Properties would be nice, I don't know of an interactive way of using that through powershell and the server has over 500 profiles on it. – Thomas Guidry Jan 27 '15 at 17:38

0 Answers0