Forum Discussion

15 Replies

  • nhtkid's avatar
    nhtkid
    Iron Contributor

    Hi Jannik_Reinhard and Rudy_Ooms_MVP,

    Thanks for sharing this.

    I am keen to try it too.

     

    However, I have machines running in Kiosk mode (Windows 10 Multi Kiosk Profile deployed by Intune).

    Would either the method (Storage Sense or Proactive remediations with your scripts) work under the user-less context? Are those related Windows CSP device or user scoped?

     

    Me reading the Storage Sense Doc, it keeps saying "Deleting files for users", etc.

     

    Thank you.

  • Jannik his option is indeed a good one... combining it with storage sense... is also a smart thing to do... but still we are using our own scripting... 🙂 almost the same policy we used on our remote desktop environments

     

    This script will make sure data in all the users temp folders will be deleted. You can simply add stuff you need

    Write-Host -ForegroundColor Green "Getting the list of users"
    md c:\install -force
    dir C:\Users | select Name | Export-Csv -Path C:\install\users.csv -NoTypeInformation
    $list=Test-Path C:\install\users.csv


    Write-Host -ForegroundColor Green "SECTION 1: Clearing some other stuff"

    Import-CSV -Path C:\install\users.csv -Header Name | foreach {
    Remove-item C:\Users\$($_.Name)\AppData\Local\Microsoft\Outlook\*.nst -Force -EA SilentlyContinue -Verbose
    Remove-item C:\Users\$($_.Name)\appdata\Local\Microsoft\Windows\Explorer\*.db -Force -EA SilentlyContinue -Verbose
    Remove-Item -path "C:\Users\$($_.Name)\AppData\Local\Microsoft\Teams\previous\*" -Recurse -Force -EA SilentlyContinue -Verbose
    }


    Write-Host -ForegroundColor Green "SECTION 2: Clearing Mozilla Firefox Caches"

    Import-CSV -Path C:\install\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
    Remove-item C:\Users\$($_.Name)\AppData\Local\Mozilla\Firefox\Profiles\*\Cache2\* -Recurse -Force -EA SilentlyContinue -Verbose
    }


    Write-Host -ForegroundColor Green "SECTION 3: Clearing Google Chrome Caches"

    Import-CSV -Path C:\install\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
    Remove-Item -path "C:\Users\$($_.Name)\AppData\Local\Google\Chrome\User Data\Default\Service Worker\CacheStorage\*" -Recurse -Force -EA SilentlyContinue -Verbose
    }


    Write-Host -ForegroundColor Green "SECTION 4: Clearing Internet Explorer Caches"

    Import-CSV -Path C:\install\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\Microsoft\Windows\inetcache\*" -Recurse -Force -EA SilentlyContinue -Verbose
    Remove-Item -path "C:\Users\$($_.Name)\AppData\Local\Temp\*" -Recurse -Force -EA SilentlyContinue -Verbose
    Remove-Item -path "C:\Users\$($_.Name)\AppData\Local\Microsoft\Windows\webcache\*" -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
    Remove-Item -path "C:\Users\$($_.Name)\AppData\Local\Microsoft\Edge\User Data\Default\Cache\*" -Recurse -Force -EA SilentlyContinue -Verbose
    Remove-Item -path "C:\Users\$($_.Name)\AppData\Local\Microsoft\Edge\User Data\Default\Code Cache\*" -Recurse -Force -EA SilentlyContinue -Verbose
    Remove-Item -path "C:\Users\$($_.Name)\AppData\Local\Microsoft\Edge\User Data\Default\Service Worker\CacheStorage\*" -Recurse -Force -EA SilentlyContinue -Verbose
    }

  • Yes this is possible via a simple endpoint analytics remediation script. Do you have specific folders wo want to delete?
    If you want I can provide you the script.
    • AB21805's avatar
      AB21805
      Bronze Contributor
      Yes please!

      App data local & roaming
      Any other system files that take up space really do you have any in mind?

Resources