Kaseya Community

Script to clear disk space on servers

This question is not answered

Hi , 

My client need some scripts to do self healing in case any alerts are found for low disk space on servers and workstations.Can anybody share the procedure with me to do the disk cleanups on servers and workstations that can be utilized in monitor sets??

All Replies
  • Just a couple options to run procedure with these details.

    Deletes everything in C:\Temp folder older than 30 days

    executeShellCommand with: Forfiles.exe -p C:\Temp\ -m *.* -d -30 -c "Cmd.exe /C del @path" -s

    Deletes all the memory.dmp older than 30 days

    executeShellCommand with: Forfiles.exe -p C:\Windows\ -m memory.dmp -d -30 -c "Cmd.exe /C del @path" -s

    Empties everybody's C: Recycle Bin. 

    executeShellCommand with: rd /s /q "c:\$Recycle.Bin"

    if testFile C:\Windows\System32\LogFiles\W3SVC1\nul

    executeShellCommand Forfiles.exe -p C:\Windows\System32\LogFiles\W3SVC1\ -m *.log -d -30 -c "Cmd.exe /C del @path" -s

    if testFile C:\inetpub\logs\LogFiles\W3SVC1\nul

    executeShellCommand Forfiles.exe -p C:\inetpub\logs\LogFiles\W3SVC1\ -m *.log -d -30 -c "Cmd.exe /C del @path" -s

    You would still need to have the procedure email for the alerting function.  I used a modification of the vbs to recheck the drives afterwards.  It writes an event log and then you can have Event Log monitoring setup to look for WSH 1 or 2 and alert on that.

    http://community.kaseya.com/resources/m/knowexch/55179.aspx

     

     

  • Hi Lethal,

    Thanks a lot for your revert . This is useful but the thing is that I am pretty much new to scripting part so can you send me the Script that you have used for clearing the disk space and I can import that in my VSA and test it on the machine so that the same can be implemented in Kaseya.

  • Unfortunately I have other stuff in my procedures that would not help you.  If I get time, I will try and clean one up, but to do it right, you will need to dig into the scripting.  You can do the above quickly.

    #1)  Create new procedure

    #2)  Drag executeShellCommand onto the procedure.

    #3)  Paste in Forfiles.exe -p C:\Temp\ -m *.* -d -30 -c "Cmd.exe /C del @path" -s

    #4)  Save.

    #5)  Run procedure against a test machine and see if files older than 30 days are deleted.

    Once you have that idea down, you can implement the rest and grow from it.

  • I have added the shell command in the script and it cleared the files in Recycle bin but no file has been deleted from Temp folder , just to confirm we have to add this command in the command shell "Forfiles.exe -p C:\Temp\ -m *.* -d -30 -c "Cmd.exe /C del @path" -s" and if the answer is yes then this is not working in y case. Please help

  • Try some of the newer cleanup methods:

    7/8/8.1 / 2008R2/2012 service pack cleanup: Dism.exe /online /Cleanup-Image /SPSuperseded

    vista sp2 cleanup: compcln.exe

    vista sp1 cleanup: vsp1cln.exe

    8.1 / 2012 R2 superseded winsxs image cleanup: Dism.exe /online /Cleanup-Image /StartComponentCleanup

    I then use ccleaner portable to get rid of temp files and so on.

  • Procedure DiskCleanup - Cleanmgr.exe.xml

    Can somebody help me in this



    Can somebody help me in this script for disk cleanup . It runs successfully on win7 machines but failed on servers 2008 .
    [edited by: Abhishek11 at 12:39 AM (GMT -7) on Jul 25, 2014]
  • Servers do not come with CleanMgr installed. You can add the "Desktop Feature" for it, but that requires a reboot. Instead of that, script these steps to copy two files:

    www.toms-blog.com/installing-disk-clean-up-tool-in-windows-server-2008

    Two other tools worth check out are ICSweep and DelProf2. Also, consider reducing pagefile size on C: (no lower than 800MB) and turn off shadow copies if there are no shares.

  • I have added the 2 files as required on the machine C: but still cleanmgr does not perform its function through the script as can be seen through screenshot but when i try to manually run cleanmgr through command prompt result is successful . Can somebody help me as what is the exact error i am facing in script.

  • Script error.jpg

    Attached is the screenshot

  • screenshot.jpg

    Also the attached file is available as can be seen in the screenshot.

  • The error looks to be telling you that on line 25 it's referencing a file that's not found.

    Can you share the vbs script?

  • Procedure DiskCleanup - Cleanmgr.exe.xml

    Hey Alistair,

    I am very new to this scripting part and want this script to work on both servers as well as worksatations. Please help

  • It's the contents of the file DIskClean.vbs file I need to see.  The one I have doesn't reference anything on that line.  Can you post here as a text file.

  • DiskCleanup - Cleanmgr.txt

    Hi,

    PFA as per your requirement

  • Leathel, when you're testing for c:\windows\system32\logfiles\W3SVC1\buk, are you testing to see if it exists? Or does not exist?