Kaseya Community

Find Large Files

  • A new script I wrote today when I had a drive getting full on a server, and I needed to find out what was taking up all the space...

    By default this script searches the C: drive for any files larger than 10MB and sends an email and writes to the script log., The Drive letter and size can be easily changed with a quick edit of the script.

    NOTE: this script may take a bit of time to run, especially on large drives.

    Note: You will need to download and add the following files to your KServer.
    xargs.exe, find.exe, and du.exe
    - from the unixutils package http://unxutils.sf.net, note the download from this info page is broken, you can get the actual zip file here ftp://garbo.uwasa.fi/win95/unix/UnxUtils.zip

    Script Name: Find Large Files
    Script Description: This utility can be used to find files taking up a lot of disk space. It uses the find.exe, xargs.exe, and du.exe utilities from Unixutils.sf.net By default it's looking for files larger than 10MB

    IF True
    THEN
    Get Variable
    Parameter 1 : 10
    Parameter 2 :
    Parameter 3 : tempPath
    OS Type : 0
    Get Variable
    Parameter 1 : 6
    Parameter 2 :
    Parameter 3 : #machineID#
    OS Type : 0
    Write File
    Parameter 1 : #tempPath#\find.exe
    Parameter 2 : VSASharedFiles\find.exe
    OS Type : 0
    Write File
    Parameter 1 : #tempPath#\xargs.exe
    Parameter 2 : VSASharedFiles\xargs.exe
    OS Type : 0
    Write File
    Parameter 1 : #tempPath#\du.exe
    Parameter 2 : VSASharedFiles\du.exe
    OS Type : 0
    Execute Shell Command
    Parameter 1 : #tempPath#\find.exe c:\ -size +10240k | #tempPath#\xargs -n 1 --replace={} #tempPath#\du -sh \"{}\" >> #tempPath#\findlog.txt
    Parameter 2 : 1
    OS Type : 0
    Get Variable
    Parameter 1 : 1
    Parameter 2 : #tempPath#\findlog.txt
    Parameter 3 : LargeFiles
    OS Type : 0
    Send Email
    Parameter 1 : myemail@address.com
    Parameter 2 : Here are is your large file Listing for #machineID#
    Parameter 3 : #LargeFiles#
    OS Type : 0
    Write Script Log Entry
    Parameter 1 : Large Files #LargeFiles#
    OS Type : 0
    Delete File
    Parameter 1 : #tempPath#\findlog.txt
    OS Type : 0
    Delete File
    Parameter 1 : #tempPath#\find.exe
    OS Type : 0
    Delete File
    Parameter 1 : #tempPath#\du.exe
    OS Type : 0
    Delete File
    Parameter 1 : #tempPath#\xargs.exe
    OS Type : 0
    ELSE




    Legacy Forum Name: Find Large Files,
    Legacy Posted By Username: Jonathan
  • Hi Jonathan,

    Any chance there is another link to those downloads as neither seem to work.

    Thanks

    Angeline

  • Why not just use built in commands instead of pushing utilities that aren't needed?

    Example:


    forfiles /P c:\ /S /C "cmd /c  if @fsize gtr 10000000 echo @path is @fsize" >> #tempPath#\findlog.txt

     

     

    /necro off

     



    [edited by: Dan at 6:40 AM (GMT -7) on 8-23-2011] d
  • I used Dan's command as a basis for a file check  in the following script;

     <?xml version="1.0" encoding="utf-8" ?>

    - <ScriptExport xmlns:xsi="www.w3.org/.../XMLSchema-instance" xmlns:xsd="www.w3.org/.../XMLSchema" xmlns="www.kaseya.com/.../Scripting">

    - <Procedure name="Check for .xml-debug and e-mail" treePres="3" id="1154159343" folderId="82411979893418891176216519">

    - <Body description="Checck for .xml-debug files in the C:\kworking folder above a certain size (1 MB). If a file is found, e-mail e-mail1 and e-mail2.">

    - <Statement description="Execute the given command as if it were typed in at a command prompt." name="ExecuteShellCommand" continueOnFail="false" osType="Windows">

     <Parameter xsi:type="StringParameter" name="Command" value="forfiles /S /M *.xml-debug /P C:\kworking\ /C "cmd /c if @fsize gtr 1048576 echo @path is @fsize >> C:\kworking\xml-debug.log"" />

     <Parameter xsi:type="EnumParameter" name="ExecuteAccount" value="System" />

     <Parameter xsi:type="BooleanParameter" name="Is64Bit" value="False" />

     </Statement>

    - <If description="If forfiles command writes a log file...">

    - <Condition name="TestFile">

     <Parameter xsi:type="StringParameter" name="Path" value="C:\kworking\xml-debug.log" />

     <Parameter xsi:type="EnumParameter" name="Condition" value="Exists" />

     <Parameter xsi:type="StringParameter" name="Value" value="" />

     </Condition>

    - <Then>

    - <Statement description="Send an email from the server (address specified in the Configure function in the System module)." name="SendEmail" continueOnFail="false" osType="Windows">

     <Parameter xsi:type="StringParameter" name="To" value="e-mail1@address.com,e-mail2@address.com" />

     <Parameter xsi:type="StringParameter" name="Subject" value="C:\kworking\xml-debug.log exists on #vAgentConfiguration.machName# in group #vAgentConfiguration.groupName#!" />

     <Parameter xsi:type="StringParameter" name="Body" value="This computer #vAgentConfiguration.machName# in group #vAgentConfiguration.groupName# has a .xml-debug file over 1 MB is size!" />

     </Statement>

     </Then>

     </If>

     </Body>

     </Procedure>

     </ScriptExport>

  • I created a Powershell script which outputs similar information. The advantage of creating your own script is the formatting, which makes it easy to further process the data.

  • Stefan,

       Can you post your Powershell script?

  • looks good, is there any way to then move/copy the lare files to another location based on the results from the find command?

  • In the Agent Procedure I am using, if a file is found above a certain size (1 MB) then a log file is made.  Then Kaseya checks for the existance of that log file.  If it is found it e-mails the addresses.  You could add a step after the e-mail step to copy the file off somewhere like C:\kworking\keep\ or to a network share.  I am still working on this Agent Procedure and will eventually delete the file and the log file.

    The reason I did not copy the file I am checking (.xml-debug) is because it can become insanely large.  In the hundreds of GB size.  If the Procedure tries to copy it somewhere else it could quickly use up the entire drive.

    If you know the file will be manageable and small, then you could copy it off somewhere else.

    P.S.  These .xml-debug files were a known issue and patched with a hotfix by Kaseya.  The latest kdpm installer should be ran to make sure kdpm is at 3.5.

    download.kaseya.com/.../kdpminstall.exe

  • Aelser: this is the Powershell script I wrote. You have to specify the minimum size (in MB's) of the files you want to filter. The script checks every logical drive on the system you're running the script on.

    Let me know if you need help with this.

     

    #########################################################################

    #

    #

    # This script shows the files which are larger than the amount of MB's

    # passed as the first parameter

    # Parameters:

    #  1. Minimum size of the file (in MB)

    #

    #########################################################################

     

    [int]$size = $args[0];

     

    $disks = Get-WmiObject -class Win32_PerfRawData_PerfDisk_LogicalDisk;

     

    foreach ($disk in $disks) {

        if ($disk.Name -ne "_Total" -AND !$disk.Name.Contains("HarddiskVolume")) {

            $name = $disk.Name + "\";

            $files = Get-ChildItem -path $name -recurse -ea SilentlyContinue | 

            where  { ($_.Length / 1MB) -gt $size } |

            Sort-Object Length -Descending

     

            $output = "Files larger than " + $size.toString()+ " MB on disk " + $name + "`r`n";

            $output += "`r`n";

            foreach ($file in $files) {

                if ($file.Name) {

                    $output += "File:      " + $file.Name + "`r`n";

                    $output += "Directory: " + $file.DirectoryName + "`r`n";

                    $output += "Size:      {0:n2}" -f ($file.Length / 1MB) + " MB`r`n";

                    $output += "`r`n";

                }

            }

        }

    }

     

    $output