Tuesday 4 July 2017

Delete temp files using group policy logon script

Or, Logon script for deleting temp files from windows directory using group policy
Or, Temp file deletion group policy for windows machines

Description: You can create a .bat file using the script given below and can use it in group policy logon script section.

Open Notepad > Paste this script (modify the folders path as per your requirements) > save this file as tempdeletion.bat
set folder="%temp%"
cd /d %folder%
for /F "delims=" %%i in ('dir /b') do (rmdir "%%i" /s/q || del "%%i" /s/q)
set folder="C:\Windows\Temp"
cd /d %folder%
for /F "delims=" %%i in ('dir /b') do (rmdir "%%i" /s/q || del "%%i" /s/q)
set folder="%localappdata%\Microsoft\Windows\INetCache\IE"
cd /d %folder%
for /F "delims=" %%i in ('dir /b') do (rmdir "%%i" /s/q || del "%%i" /s/q)

In my case, I have taken following temp directory path in the above script:

Once you have the .bat script ready with you, you can use this script as logon script in any GPO and link with any OU as per your requirements.

Cheers, let me know if you have any query or feedback.

No comments:

Post a Comment