Kaseya Community

Script to find a specific extension and report back if larger than X

This question is answered

I am trying to write a script that scans a hard drive for the .qbw extension and reports back with the file path if the .qbw file is larger than 200 mb. If it finds a .qbw file larger than 200 MB I would like it to fire off an email.

so far I am able to do the search using CMD utilities. This scan will report back the path and size of any files with .qbw extension.

this is what I am using so far - forfiles /p H:\ /s /m *.qbw /c "cmd /c echo @path @fsize"

The issue is how do I parse this data to find the files larger than 200 MB.

I am open to any other suggestions on how to do this.

Verified Answer
  • The below will only return files > 200MB, if you want to see all files with size, or re-arrange how the .log file is formatted let me know, those are simple fixes. 

     

    Save the code below as yourscript.vbs file and add it to your kserver in managed files. Create a new procedure (call it what you like) and create the following:

    Step:

    1. write File c:\yourscript.vbs

    2.Execute Shell command c:\yourscript.vbs    (or use) Execute Vbscript c:\yourscript.vbs

    3. Get Variable File Content C:\Results.log save as #results#

    4. email <yourself> #results# 

     

    Hope this helps. 

     

     

    On Error Resume Next 

    Dim filetxt, FSO, objDir, ftype

    Const ForReading = 1, ForWriting = 2, ForAppending = 8

    Set FSO = CreateObject("Scripting.FileSystemObject")

    Set objDir = FSO.GetFolder("c:\") ' this sets where to look

    If FSO.FileExists("c:\Results.log") Then FSO.DeleteFile("c:\Results.log")

    ftype = "qbw"

    file objDir

     

    sub file(objDir)

     

    For Each i In objDir.Files

    If LCase(Right(Cstr(i.Name), 3)) = ftype AND i.Size >= 209715200 Then

    Set filetxt = FSO.OpenTextFile("c:\Results.log", ForAppending, True)

    path = FSO.GetAbsolutePathName(i)

    filetxt.WriteLine(path & " = " & fsize(i.Size))

    filetxt.Close

    End If

    Next

    For Each i In objDir.SubFolders

    file(i) 

    Next

     

    End sub 

     

    Function fsize(Bytes)

        If Bytes > 0 And Bytes < 1024 Then

                fsize = Bytes&" Bytes"

            ElseIf Bytes >= 1024 And Bytes < 1048576 Then

                fsize = Round(Bytes/1024)&" KB"

            ElseIf Bytes >= 1048576 And Bytes < 1073741824 Then

                fsize = Round(Bytes/1048576)&" MB"

            ElseIf Bytes >= 1073741824 Then

                fsize = Round(Bytes/1073741824) &" GB"

        End IF

    End Function



    [edited by: danrche at 11:34 PM (GMT -7) on 3-23-2011] tweeking script
All Replies
  • The below will only return files > 200MB, if you want to see all files with size, or re-arrange how the .log file is formatted let me know, those are simple fixes. 

     

    Save the code below as yourscript.vbs file and add it to your kserver in managed files. Create a new procedure (call it what you like) and create the following:

    Step:

    1. write File c:\yourscript.vbs

    2.Execute Shell command c:\yourscript.vbs    (or use) Execute Vbscript c:\yourscript.vbs

    3. Get Variable File Content C:\Results.log save as #results#

    4. email <yourself> #results# 

     

    Hope this helps. 

     

     

    On Error Resume Next 

    Dim filetxt, FSO, objDir, ftype

    Const ForReading = 1, ForWriting = 2, ForAppending = 8

    Set FSO = CreateObject("Scripting.FileSystemObject")

    Set objDir = FSO.GetFolder("c:\") ' this sets where to look

    If FSO.FileExists("c:\Results.log") Then FSO.DeleteFile("c:\Results.log")

    ftype = "qbw"

    file objDir

     

    sub file(objDir)

     

    For Each i In objDir.Files

    If LCase(Right(Cstr(i.Name), 3)) = ftype AND i.Size >= 209715200 Then

    Set filetxt = FSO.OpenTextFile("c:\Results.log", ForAppending, True)

    path = FSO.GetAbsolutePathName(i)

    filetxt.WriteLine(path & " = " & fsize(i.Size))

    filetxt.Close

    End If

    Next

    For Each i In objDir.SubFolders

    file(i) 

    Next

     

    End sub 

     

    Function fsize(Bytes)

        If Bytes > 0 And Bytes < 1024 Then

                fsize = Bytes&" Bytes"

            ElseIf Bytes >= 1024 And Bytes < 1048576 Then

                fsize = Round(Bytes/1024)&" KB"

            ElseIf Bytes >= 1048576 And Bytes < 1073741824 Then

                fsize = Round(Bytes/1048576)&" MB"

            ElseIf Bytes >= 1073741824 Then

                fsize = Round(Bytes/1073741824) &" GB"

        End IF

    End Function



    [edited by: danrche at 11:34 PM (GMT -7) on 3-23-2011] tweeking script
  • This worked perfectly! Thanks Danrche!

  • esabo

    This worked perfectly! Thanks Danrche!

    you're welcome