Forum Discussion
free up space by deleting temp files via intune
Hi all,
Is it possible to delete files which are possible to delete to get more space on devices via intune or scripting?
15 Replies
- nhtkidIron 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
}- AB21805Bronze Contributor
- Jannik_ReinhardIron ContributorAB21805: You can combine both. You can add the cleanup script from Rudy_Ooms_MVP to my remediation script.
- NielsScheffersIron Contributor
As an alternative, you can also consider configuring Storage Sense, as described on Manage drive space with Storage Sense (microsoft.com). Among other things, this allows you to (automatically) clean up temporary files when disk space runs low.
Also, check out this blog on how to configure it with Settings Catalog:
How To Configure Storage Sense Using Intune | Endpoint Manager HTMD Blog (anoopcnair.com)
- AB21805Bronze ContributorHi I have already done this but no luck with taking off much space on most devices
- Jannik_ReinhardIron ContributorYes 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.- AB21805Bronze ContributorYes please!
App data local & roaming
Any other system files that take up space really do you have any in mind?