locked
Cleaning user profiles of temp and cache files on RDS hosts RRS feed

  • Question

  • Hi,

    I have disk space issues on some RDS hosts and notice that users tend to have huge temp and cache files from their browsers. Disk Cleanup does not pick that us and neither do apps like CCleaner from my admin account. Is there a best practice to clean those user profiles and recuperate disk space in general for RDS hosts?

    Thanks for the tips in advance,

    PMD

    Wednesday, March 14, 2018 10:59 PM

All replies

  • Hi,

    For your needs, I would suggest you use group policy settings “Allow deleting browsing history on exit” and “Empty Temporary Internet Files folder when browser is closed” to clean temporally files.

    “Allow deleting browsing history on exit” is under “Computer/User Configuration – Administrative Templates – Windows Components –Internet Explorer – Delete Browsing History”, “Empty Temporary Internet Files folder when browser is closed” is under “Computer/User Configuration – Administrative Templates – Windows Components –Internet Explorer – Internet Control Panel – Advanced Page”

    Besides, we could use policy “Prevent deleting …” to control which kind files will not be delete.

    If you have anything unclear, please feel free to let me know.

    Best Regards,

    William


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.


    Thursday, March 15, 2018 3:26 AM
  • This would work for which browsers? This client uses Chrome and Firefox mostly.
    Thursday, March 15, 2018 4:44 AM
  • Hi,

    Those settings work for Internet Explorer, for Chrome and Firefox, we could create a scheduled task to clean up temp files.

    If there is anything else we can do for you, please feel free to post in the forum.

    Best Regards,

    William


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    Thursday, March 15, 2018 10:21 AM
  • Scheduled task?  What did you have in mind for this specific purpose?

    Chrome does have some group policies applicable to this, but what Firefox just shipped looks very incomplete by comparison.

    Thursday, March 15, 2018 4:25 PM
  • Hi,

    Based on my research, the following script would be helpful for you:

    Write-Host -ForegroundColor yellow "#######################################################"
    ""
    Write-Host -ForegroundColor Green "Powershell commands to delete cache & cookies in Firefox, Chrome & IE browsers"
    Write-Host -ForegroundColor Green "By Lee Bhogal, Paradise Computing Ltd - June 2014"
    Write-Host -ForegroundColor Green "VERSION: 2"
    ""
    Write-Host -ForegroundColor yellow "#######################################################"
    ""
    Write-Host -ForegroundColor Green "CHANGE_LOG:
    v2.4: - Resolved *.default issue, issue was with the file path name not with *.default, but issue resolved
    v2.3: - Added Cache2 to Mozilla directories but found that *.default is not working
    v2.2: - Added Cyan colour to verbose output
    v2.1: - Added the location 'C:\Windows\Temp\*' and 'C:\`$recycle.bin\'
    v2:   - Changed the retrieval of user list to dir the c:\users folder and export to csv
    v1:   - Compiled script"
    ""
    Write-Host -ForegroundColor yellow "#######################################################"
    ""
    #########################
    "-------------------"
    Write-Host -ForegroundColor Green "SECTION 1: Getting the list of users"
    "-------------------"
    # Write Information to the screen
    Write-Host -ForegroundColor yellow "Exporting the list of users to c:\users\%username%\users.csv"
    # List the users in c:\users and export to the local profile for calling later
    dir C:\Users | select Name | Export-Csv -Path C:\users\$env:USERNAME\users.csv -NoTypeInformation
    $list=Test-Path C:\users\$env:USERNAME\users.csv
    ""
    #########################
    "-------------------"
    Write-Host -ForegroundColor Green "SECTION 2: Beginning Script..."
    "-------------------"
    if ($list) {
        "-------------------"
        #Clear Mozilla Firefox Cache
        Write-Host -ForegroundColor Green "SECTION 3: Clearing Mozilla Firefox Caches"
        "-------------------"
        Write-Host -ForegroundColor yellow "Clearing Mozilla caches"
        Write-Host -ForegroundColor cyan
        Import-CSV -Path C:\users\$env:USERNAME\users.csv -Header Name | foreach {
                Remove-Item -path C:\Users\$($_.Name)\AppData\Local\Mozilla\Firefox\Profiles\*.default\cache\* -Recurse -Force -EA SilentlyContinue -Verbose
                Remove-Item -path C:\Users\$($_.Name)\AppData\Local\Mozilla\Firefox\Profiles\*.default\cache\*.* -Recurse -Force -EA SilentlyContinue -Verbose
    	    Remove-Item -path C:\Users\$($_.Name)\AppData\Local\Mozilla\Firefox\Profiles\*.default\cache2\entries\*.* -Recurse -Force -EA SilentlyContinue -Verbose
                Remove-Item -path C:\Users\$($_.Name)\AppData\Local\Mozilla\Firefox\Profiles\*.default\thumbnails\* -Recurse -Force -EA SilentlyContinue -Verbose
                Remove-Item -path C:\Users\$($_.Name)\AppData\Local\Mozilla\Firefox\Profiles\*.default\cookies.sqlite -Recurse -Force -EA SilentlyContinue -Verbose
                Remove-Item -path C:\Users\$($_.Name)\AppData\Local\Mozilla\Firefox\Profiles\*.default\webappsstore.sqlite -Recurse -Force -EA SilentlyContinue -Verbose
                Remove-Item -path C:\Users\$($_.Name)\AppData\Local\Mozilla\Firefox\Profiles\*.default\chromeappsstore.sqlite -Recurse -Force -EA SilentlyContinue -Verbose
                }
        Write-Host -ForegroundColor yellow "Clearing Mozilla caches"
        Write-Host -ForegroundColor yellow "Done..."
        ""
        "-------------------"
        # Clear Google Chrome 
        Write-Host -ForegroundColor Green "SECTION 4: Clearing Google Chrome Caches"
        "-------------------"
        Write-Host -ForegroundColor yellow "Clearing Google caches"
        Write-Host -ForegroundColor cyan
        Import-CSV -Path C:\users\$env:USERNAME\users.csv -Header Name | foreach {
                Remove-Item -path "C:\Users\$($_.Name)\AppData\Local\Google\Chrome\User Data\Default\Cache\*" -Recurse -Force -EA SilentlyContinue -Verbose
    Remove-Item -path "C:\Users\$($_.Name)\AppData\Local\Google\Chrome\User Data\Default\Cache2\entries\*" -Recurse -Force -EA SilentlyContinue -Verbose
                Remove-Item -path "C:\Users\$($_.Name)\AppData\Local\Google\Chrome\User Data\Default\Cookies" -Recurse -Force -EA SilentlyContinue -Verbose
                Remove-Item -path "C:\Users\$($_.Name)\AppData\Local\Google\Chrome\User Data\Default\Media Cache" -Recurse -Force -EA SilentlyContinue -Verbose
                Remove-Item -path "C:\Users\$($_.Name)\AppData\Local\Google\Chrome\User Data\Default\Cookies-Journal" -Recurse -Force -EA SilentlyContinue -Verbose
                # Comment out the following line to remove the Chrome Write Font Cache too.
                # Remove-Item -path "C:\Users\$($_.Name)\AppData\Local\Google\Chrome\User Data\Default\ChromeDWriteFontCache" -Recurse -Force -EA SilentlyContinue -Verbose
                }
    
        Write-Host -ForegroundColor yellow "Done..."
        ""
        "-------------------"
        # Clear Internet Explorer
        Write-Host -ForegroundColor Green "SECTION 5: Clearing Internet Explorer Caches"
         "-------------------"
        Write-Host -ForegroundColor yellow "Clearing Google caches"
        Write-Host -ForegroundColor cyan
        Import-CSV -Path C:\users\$env:USERNAME\users.csv | foreach {
                Remove-Item -path "C:\Users\$($_.Name)\AppData\Local\Microsoft\Windows\Temporary Internet Files\*" -Recurse -Force -EA SilentlyContinue -Verbose
    	    Remove-Item -path "C:\Users\$($_.Name)\AppData\Local\Microsoft\Windows\WER\*" -Recurse -Force -EA SilentlyContinue -Verbose
    	    Remove-Item -path "C:\Users\$($_.Name)\AppData\Local\Temp\*" -Recurse -Force -EA SilentlyContinue -Verbose
    	    Remove-Item -path "C:\Windows\Temp\*" -Recurse -Force -EA SilentlyContinue -Verbose
    	    Remove-Item -path "C:\`$recycle.bin\" -Recurse -Force -EA SilentlyContinue -Verbose
                }
    
        Write-Host -ForegroundColor yellow "Done..."
        ""
        Write-Host -ForegroundColor Green "All Tasks Done!"
        } else {
    	Write-Host -ForegroundColor Yellow "Session Cancelled"	
    	Exit
    	}

    Original link of the script above:

    https://github.com/lemtek/Powershell/blob/master/Clear_Browser_Caches

    Please Note: Since the web site is not hosted by Microsoft, the link may change without notice. Microsoft does not guarantee the accuracy of this information.

    Best Regards,

    William


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.



    Monday, March 19, 2018 2:31 AM
  • Hi,

     

    Was your issue resolved?

     

    If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.

    If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.

    If no, please reply and tell us the current situation in order to provide further help.

     

    Best Regards,

    William


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    Wednesday, March 21, 2018 10:04 AM
  • Hi,

     

    Just want to confirm the current situations.

    Please feel free to let us know if you need further assistance.

     

    Best Regards,

    William


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    Friday, March 23, 2018 1:29 PM
  • Hi,

     

    Please remember to mark useful reply as answer, which would be much more efficient for other forum community members to find useful information.

     

    Best Regards,

     

    William


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    Monday, March 26, 2018 9:21 AM
  • Hi,

     

    Please remember to mark useful reply as answer, which would be much more efficient for other forum community members to find useful information.

     

    Best Regards,

     

    William


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    Monday, April 9, 2018 1:01 PM
  • Hi,

    Unfortunately this script is not working well. Also tried to run it as Administrator...

    I`m using Windows Server 2012 R2.

    I have tried to run it as .bat and ps1 files.

    Thursday, September 13, 2018 6:59 AM
  • Can you narrow what part is not working well?

    One issue I see is this (if a PC is named that way):

    https://github.com/lemtek/Powershell/issues/6

    There's also this, but it's just a typo in the messaging:

    https://github.com/lemtek/Powershell/issues/5

    Otherwise, the script is a few years old now, and Firefox has undergone a complete revamp in that time. Some of the paths/file names might have changed, so check over each one and compare it to what you actually have installed.

    Thursday, September 13, 2018 6:30 PM