Seems like a simple task but none of my solutions have worked. Regular AD domain with regular users. We use terminal servers with non-roaming profiles so everything is stored on the TS disk. We want to empty their downloads folder at login because they never do it themselves and we're tired of having the disks fill up.
So, naturally I make a simple powershell script and create a GPO to run it at logon. Problem is, the ps script required elevation, and logon scripts run at that user's permission level and cannot be elevated.
Here's the PS line:
Get-ChildItem C:\Users\*\Downloads\* | Remove-Item -Force
Works great if you manually run it from an elevated powershell instance.
Ok so no GPO. Next thought is to create a scheduled task on each terminal server and run with a service account that has admin privilege.
Problem there is that it doesn't work to empty each user's download folder... only the service account's.
So- I don't want to statically type each and every user's download folder path into the .ps1 file, because obviously that would be a management nightmare.
So does anybody know:
- A way to empty the download folder on user login through a GPO without running a script to do it. or
- A way to improve the script to recursively look through each user's folder, find the downloads folder, and empty it.. without having to specify the name of each user.
How can this easily be done? Thanks