Kaseya Community

Searching for directories or files

  • Hello All,
    I was really looking for help on this one - I need a script either built in or one Id have to create to search my networked computers for the existance of a specific directory or file. Then report back the computer with those directories or files...It would also be nice to be able to delete those directories if they exist. Does a script exist for such a need?

    Thanks in advance


    Legacy Forum Name: Searching for directories or files,
    Legacy Posted By Username: KASEYANUBE
  • I am looking to do the same thing. Especially to search across multiple directories.

    David Johnson


    Legacy Forum Name: Script Discussion,
    Legacy Posted By Username: effective
  • Imported Empty Post

    Legacy Forum Name: Script Discussion,
    Legacy Posted By Username: effective
  • We developed this inhouse and it seems to work well. In step 4 ("dir #searchdrive#*.pst /s"), simply replace .pst with file extension you're looking for. IMPORTANT: In step 7, be sure to enter your email address (without parenthesis or *). I just posted to shared scripts so it should be up there soon; in the meantime, here you go:

    Script Name: findfiles
    Script Description: Searches for all files with .pst (more can be added) and outputs the result into the client's script log and via email. Edit the script to change the type of files and email behavior.

    IF True
    THEN
    Get Variable
    Parameter 1 : 4
    Parameter 2 :
    Parameter 3 : searchdrive
    OS Type : 0
    Get Variable
    Parameter 1 : 6
    Parameter 2 :
    Parameter 3 : machineid
    OS Type : 0
    Execute Shell Command - (Continue on Fail)
    Parameter 1 : mkdir "#searchdrive#Temp"
    Parameter 2 : 1
    OS Type : 0
    Execute Shell Command
    Parameter 1 : dir #searchdrive#*.pst /s >> #searchdrive#TempFext.txt
    Parameter 2 : 1
    OS Type : 0
    Get Variable
    Parameter 1 : 1
    Parameter 2 : #searchdrive#TempFext.txt
    Parameter 3 : foundfiles
    OS Type : 0
    Write Script Log Entry
    Parameter 1 : #foundfiles#
    OS Type : 0
    Send Email
    Parameter 1 : (*****ENTER EMAIL ADDRESS HERE******)
    Parameter 2 : Files found on #machineid#
    Parameter 3 : #foundfiles#
    OS Type : 0
    Delete File
    Parameter 1 : #searchdrive#TempFext.txt
    OS Type : 0
    ELSE









    Legacy Forum Name: Script Discussion,
    Legacy Posted By Username: billtei
  • samplereport.JPG
    I've used this script many times, however recently there was a situation where we needed to be able to develop a simple report for a client of all MP3 files on all of the computers in their network. This script works for single computers, but then taking the indivual emails and trying to combine them into one solid report is a bit of a pain. It also logs to the script log which gives you the beginnings of a decent report, unfortunately the formatting of the output date leaves much to be desired.

    Given all of that I've written a new version of the find files script that puts the formatting of the report a bit more clean, and works great for what we were looking for. Currently it only prints the full path to the file, and the size in Bytes. This can be modified by tweaking the parameters of the printf statement.

    I've attached a sample screenshot of the report output from a single machine when searching for jpg files. The one oddity of this is that when Kaseya breaks things into individual entries to make it fit into the script log it tends to drop some info out, as you can see in the highlighted portion..

    You'll need to add the find.exe file from the UnixUtils package, available here
    ftp://garbo.uwasa.fi/win95/unix/UnxUtils.zip, to your Shared Files, as this script makes use of it.


    Script Name: Find Files
    Script Description: Searches for all files with .pst (more can be added) and outputs the result into the client's script log. Edit the script to change the type of files. This can be used to find any file, etc...

    This script uses the find.exe utility from UnixUtils available at
    ftp://garbo.uwasa.fi/win95/unix/UnxUtils.zip

    IF True
    THEN
    Get Variable
    Parameter 1 : 10
    Parameter 2 :
    Parameter 3 : TempPath
    OS Type : 0
    Write File
    Parameter 1 : #TempPath#\find.exe
    Parameter 2 : VSASharedFiles\find.exe
    OS Type : 0
    Get Variable
    Parameter 1 : 4
    Parameter 2 :
    Parameter 3 : searchdrive
    OS Type : 0
    Execute Shell Command
    Parameter 1 : #TempPath#\find.exe #searchdrive# -name *.mp3 -printf "%p %s<
    >\n" >> #TempPath#\found.txt
    Parameter 2 : 1
    OS Type : 0
    Get Variable
    Parameter 1 : 1
    Parameter 2 : #TempPath#\found.txt
    Parameter 3 : foundfiles
    OS Type : 0
    Write Script Log Entry
    Parameter 1 : #foundfiles#
    OS Type : 0
    Delete File
    Parameter 1 : #TempPath#\find.exe
    OS Type : 0
    Delete File
    Parameter 1 : #TempPath#\found.txt
    OS Type : 0
    ELSE




    Legacy Forum Name: Script Discussion,
    Legacy Posted By Username: Jonathan
  • Ok, I've already modified this again.. I ran against a machine that had multiple partitions, and this only searched the drive that Kaseya was installed to. Given that I've extended the script yet again, to now search all local Fixed Disks... You'll need to create a file named drives.vbs and add it to your shared files. The contents of this file should look like so
    set FileSystemObject = CreateObject("Scripting.FileSystemObject")
    Set Drives = FileSystemObject.Drives
    Set wshShell = wscript.CreateObject("WScript.Shell")
    DrivePaths = ""
    for Each DiskDrive in Drives
    if DiskDrive.DriveType = "2" Then
    DrivePaths = DrivePaths & DiskDrive.DriveLetter & ":\ "
    End If
    Next
    wscript.echo DrivePath


    Here is the latest version of this script.
    Script Name: Find Files (Better Logging)
    Script Description: Searches for all files with .pst (more can be added) and outputs the result into the client's script log. Edit the script to change the type of files. This can be used to find any file, etc...

    This script uses the find.exe utility from UnixUtils available at
    ftp://garbo.uwasa.fi/win95/unix/UnxUtils.zip

    IF True
    THEN
    Get Variable
    Parameter 1 : 10
    Parameter 2 :
    Parameter 3 : TempPath
    OS Type : 0
    Write File
    Parameter 1 : #TempPath#\find.exe
    Parameter 2 : VSASharedFiles\find.exe
    OS Type : 0
    Write File
    Parameter 1 : #TempPath#\drives.vbs
    Parameter 2 : VSASharedFiles\drives.vbs
    OS Type : 0
    Execute Shell Command
    Parameter 1 : cscript /nologo #TempPath#\drives.vbs >> #TempPath#\drives.txt
    Parameter 2 : 1
    OS Type : 0
    Get Variable
    Parameter 1 : 1
    Parameter 2 : #TempPath#\drives.txt
    Parameter 3 : #searchdrive#
    OS Type : 0
    Execute Shell Command
    Parameter 1 : #TempPath#\find.exe #searchdrive# -name *.pst -printf "%p %s<
    >\n" >> #TempPath#\found.txt
    Parameter 2 : 1
    OS Type : 0
    Get Variable
    Parameter 1 : 1
    Parameter 2 : #TempPath#\found.txt
    Parameter 3 : foundfiles
    OS Type : 0
    Write Script Log Entry
    Parameter 1 : #foundfiles#
    OS Type : 0
    Delete File
    Parameter 1 : #TempPath#\find.exe
    OS Type : 0
    Delete File
    Parameter 1 : #TempPath#\found.txt
    OS Type : 0
    Delete File
    Parameter 1 : #TempPath#\drives.txt
    OS Type : 0
    ELSE



    Legacy Forum Name: Script Discussion,
    Legacy Posted By Username: Jonathan
  • Is this the latest VBS script? When I run cscript drives.vbs, I received just a blank line, and no content.

    Thanks,

    Michael


    Legacy Forum Name: Script Discussion,
    Legacy Posted By Username: mkenwood
  • Apparently when I copied and pasted the script in here, it cut off one character at the end...

    That last line should read
    wscript.echo DrivePaths


    Rather than
    wscript.echo DrivePath



    Legacy Forum Name: Script Discussion,
    Legacy Posted By Username: Jonathan
  • That did the trick. Very handy script.

    Thanks again,

    Michael


    Legacy Forum Name: Script Discussion,
    Legacy Posted By Username: mkenwood
  • Find_Files.zip
    I found a error on step 5, you had the varible set to "#searchdrive#" but you can't put the "#" in there, thats only after you define the variable. I also made the the other change to your VB Script so here it is all working.

    I also created a new step 1 that sets the file type you are searching for so you don't have to scroll down on the script and change the entry in the command you run. I think it makes it easier and quicker to change personally.

    There is also no need to delete the files, if the 'find.exe' or 'drives.vbs' are ever updated Kaseya will see that and upload the new files and overwrite what is there. Also the output files will be overwrited the next time the script is ran. I could see where you would want to look at the output files without having to run the script again which can take while.

    I also created the 'drives.vbs' and extracted the 'find.exe' file and ziped them and attached them so no need to download the entire Unix util thing.

    Thank you for the work on this Jonathon, hope you don't mind me updating this alittle :-)

    drives.vbs
    set FileSystemObject = CreateObject("Scripting.FileSystemObject")
    Set Drives = FileSystemObject.Drives
    Set wshShell = wscript.CreateObject("WScript.Shell")
    DrivePaths = ""
    for Each DiskDrive in Drives
    if DiskDrive.DriveType = "2" Then
    DrivePaths = DrivePaths & DiskDrive.DriveLetter & ": "
    End If
    Next
    wscript.echo DrivePaths


    Script Code
    Script Name: Find Files (Better Logging)
    Script Description: Searches for all files with .pst (more can be added) and outputs the result into the client's script log. Edit the script to change the type of files. This can be used to find any file, etc...

    This script uses the find.exe utility from UnixUtils available at
    ftp://garbo.uwasa.fi/win95/unix/UnxUtils.zip

    IF True
    THEN
    Get Variable
    Parameter 1 : 2
    Parameter 2 : *.pst
    Parameter 3 : FileType
    OS Type : 0
    Get Variable
    Parameter 1 : 10
    Parameter 2 :
    Parameter 3 : TempPath
    OS Type : 0
    Write File
    Parameter 1 : #TempPath#find.exe
    Parameter 2 : VSASharedFilesfind.exe
    OS Type : 0
    Write File
    Parameter 1 : #TempPath#drives.vbs
    Parameter 2 : VSASharedFilesdrives.vbs
    OS Type : 0
    Execute Shell Command
    Parameter 1 : cscript /nologo #TempPath#drives.vbs >> #TempPath#drives.txt
    Parameter 2 : 1
    OS Type : 0
    Get Variable
    Parameter 1 : 1
    Parameter 2 : #TempPath#drives.txt
    Parameter 3 : searchdrive
    OS Type : 0
    Execute Shell Command
    Parameter 1 : #TempPath#find.exe #searchdrive# -name #FileType# -printf "%p %s<
    >n" >> #TempPath#found.txt
    Parameter 2 : 1
    OS Type : 0
    Get Variable
    Parameter 1 : 1
    Parameter 2 : #TempPath#found.txt
    Parameter 3 : foundfiles
    OS Type : 0
    Write Script Log Entry
    Parameter 1 : #foundfiles#
    OS Type : 0
    ELSE



    Legacy Forum Name: Script Discussion,
    Legacy Posted By Username: rumptis
  • Has this been fully tested with Vista?

    I've only had a chance to toss it together and run a few times but it is not picking up all files. It's failing to find a pst file sitting on my desktop. Tried running as system with no luck.


    Legacy Forum Name: Script Discussion,
    Legacy Posted By Username: Masterson