microsoft_windows:cleantemp
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
microsoft_windows:cleantemp [2019/05/24 13:53] – external edit 127.0.0.1 | microsoft_windows:cleantemp [2022/11/14 03:15] (current) – rodolico | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Clean Temp Directory | + | ====== Clean Temp Files ====== |
- | Any windows machine will fill up with temporary files, and many applications do not clean up after themselves very well. The following batch file will delete all files older than 30 days in your personal | + | Any windows machine will fill up with temporary files, and many applications do not clean up after themselves very well. We have had times when a Windows Workstation had over 300 Gigabytes, just in the Windows |
- | <code bat cleantemp.bat> | + | Getting users to clean their own temp directories, |
- | echo off | + | |
- | echo " | + | |
- | forfiles /p %temp% /s /m *.* /D -30 /C "cmd /c echo @PATH" 2>nul || goto NoFiles | + | |
- | choice /m " | + | |
- | if ErrorLevel 2 goto No | + | |
- | if errorlevel 1 goto Yes | + | |
- | goto End | + | |
- | :Nofiles | + | ===== Power Shell ===== |
- | echo No files found | + | |
- | goto end | + | |
- | :No | + | This is a manual procedure. I did **not** want to have it automatic since there is a good chance of failure, and I'm not very good at Power Shell. |
- | echo Aborted | + | |
- | goto End | + | |
- | :Yes | + | This will show you how much disk space is used a part of the system, then the second command will allow you to delete it. //You must make sure no one is logged into the server// before running this. |
- | forfiles | + | |
- | echo Files Deleted | + | |
- | :end | + | ===== Code ===== |
+ | <code powershell> | ||
+ | # This gets the space used for each item, in gigabytes | ||
+ | # You can copy/paste this first block directly into PowerShell | ||
+ | # first, the system temporary directory, which never gets cleaned out by anything. | ||
+ | " | ||
+ | # Now, all users individual temp directories | ||
+ | "Users Temp {0:N2} GB" -f ((Get-ChildItem -force -recurse C: | ||
+ | # Then, Chrome' | ||
+ | " | ||
+ | " | ||
+ | # Finally, Mozilla Firefox' | ||
+ | " | ||
</ | </ | ||
- | ===== Windows System Temp Folder ===== | + | Do not blindly paste the following lines in. Make sure you know what will happen. |
+ | The following actually does the deletion. However, the -WhatIf says "show me what you'd do", so you must remove //-WhatIf// that before it will actually clean up. | ||
- | Windows has no way to easily clean up the c: | + | Note, we are only removing |
- | You can remove any files in the Windows Temp folder (c: | + | < |
- | < | + | |
Get-ChildItem –Path | Get-ChildItem –Path | ||
+ | Get-ChildItem -Path " | ||
+ | Get-ChildItem -Path " | ||
+ | Get-ChildItem -Path " | ||
+ | Get-ChildItem -Path " | ||
</ | </ | ||
- | the -WhatIf at the end of that command says "do a dry run", ie show what would happen, but don't actually do it. Remove that in order to actually clean up the system (remove the files). | ||
- | To run this, find PowerShell | + | ===== Procedure ===== |
+ | |||
+ | Strongly recommend doing the following, in order | ||
+ | - Reboot your server to ensure everyone is logged of and a minimum of processes are running | ||
+ | - Log in as an administrator | ||
+ | - Open PowerShell as an administrator | ||
+ | - Do not run any other programs | ||
+ | - Run as many/few of the above commands as desired. **Note**: This can take several minutes on a bloated system. | ||
+ | - Run the commands that only check on space first. You can then see if you want to concentrate on any particular areas. Just copy the first block of code and paste it into PowerShell | ||
+ | - Choose the commands to run from the second group. These are the actual cleanup script | ||
+ | - Run with the -WhatIf first, if desired. That will show you what will happen | ||
+ | - Run the same command again, but without the -WhatIf | ||
+ | - Uparror | ||
+ | - Erase the word -WhatIf, including the minus sign | ||
+ | - Press the Enter key | ||
+ | - Reboot Server | ||
+ | - Check your disk space | ||
+ | |||
+ | The reason we reboot the server before this procedure is to keep to a minimum which programs/ | ||
+ | |||
+ | ===== What is going on ===== | ||
+ | |||
+ | ==== C: | ||
+ | |||
+ | This is the system | ||
+ | |||
+ | ==== Users Temp ==== | ||
+ | |||
+ | Each individual user has their own temp directory, but the procedure for cleaning it out is somewhat obscure for a normal user. In this case, we assume the user is logged out (thus, | ||
+ | |||
+ | ==== Web Browser Caches ==== | ||
+ | |||
+ | All web browsers I know of cache a lot of (all of?) the pages they download off the Internet. While you can set each browser up to keep only a limited amount of information in their cache, it is easier to just clean up after the users. | ||
+ | |||
+ | Chrome keeps every single bit of Javascript it ever runs into, and appears to never clean that out, so we remove that also. Note: A user who visits very Javascript intensive sites (like Nextcloud or Google) will have a slightly longer startup time after you do this as all Javascript must be downloaded again. | ||
===== Links ===== | ===== Links ===== | ||
- | * [https:// | + | * https:// |
+ | * http:// |
microsoft_windows/cleantemp.1558724029.txt.gz · Last modified: 2019/05/24 13:53 by 127.0.0.1