Hi everyone, have a question regarding the search on Custom Inventory Rule.

I'm trying to find Windows PCs that have a locally stored Novell Groupwise archive.  The folder the archive creates is "ofoboarc" and one of the files to search for is msg.db.
However, when selecting the option within the Groupwise client, the user can choose any folder name for the archive, so in theory they would have C:\<any folder name>\ofoboarc\msg.db.

I'm trying to search using the rules DirectoryExists(C:\**\ofoboarc\) or FileExists(C:\**\ofoboarc\msg.db), however neither are coming back with any results.
If I specify the exact path to test with my test PC of DirectoryExists(C:\archive\ofoboarc\) or FileExists(C:\archive\ofoboarc\msg.db) I get a valid hit because that is the exact path I chose to have my archive. 
Dose anyone know of a way to have this work like a search since I have no way of knowing what my users have named their archive folder?

-John
0 Comments   [ + ] Show Comments

Comments

Please log in to comment

Answers

2
Hello,


unfortunately you cannot use a wildcard for DirectoryExists because files and directories search in the whole hard drive are really expensive and the inventory rules are run every time the inventory runs.
The best way is to use a script that periodically (I'd suggest not so frequently) will do the search job and then, if it will find the directory you're looking for, will record this finding creating a registry key for example or another form of ''breadcrumbs''
Then you can use a Custom Inventory rule to check for that registry key.
Kind regards 
Marco - StockTrader

Example Directory search example:
'***-----------Start of Script----------****
Option Explicit
Dim WshShell,DirQuery,strComputer,colFiles,objWMIService,objFile
Set WshShell = WScript.CreateObject("WScript.Shell")
on error resume next
WshShell.RegDelete "HKLM\Software\MyBreadCrumbs\DirFound" 'clean the previous crumbs if any
on error goto 0
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
DirQuery = "select Name from Win32_Directory where name like '%oboarc%'"
Set colFiles = objWMIService.ExecQuery(DirQuery)
For Each objFile in colFiles
WScript.Echo "Found it"
 WshShell.RegWrite"HKLM\Software\MyBreadCrumbs\DirFound",objFile.Name,"REG_SZ"
 Exit For 'considers that only directory with the name provided in the WQL statement exists.
Next
'*****---------End of Script------------*****
Answered 12/08/2014 by: StockTrader
Red Belt

  • Marco-will the scrip allow the use of those wildcards?
    • I'd suggest you to use a VBS script that you can launch through the Script engine to perform the search.
      A VBS like this could do the job..adjust it per your needs.
      P.S.: it is an impromptu example..revise it...

      '***-----------Start of Script----------****
      Option Explicit
      Dim WshShell,DirQuery,strComputer,colFiles,objWMIService,objFile
      Set WshShell = WScript.CreateObject("WScript.Shell")
      on error resume next
      WshShell.RegDelete "HKLM\Software\MyBreadCrumbs\DirFound" 'clean the previous crumbs if any
      on error goto 0
      strComputer = "."
      Set objWMIService = GetObject("winmgmts:" _
      & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

      DirQuery = "select Name from Win32_Directory where name like '%oboarc%'"

      Set colFiles = objWMIService.ExecQuery(DirQuery)

      For Each objFile in colFiles
      WScript.Echo "Found it"
      WshShell.RegWrite"HKLM\Software\MyBreadCrumbs\DirFound",objFile.Name,"REG_SZ"
      Exit For 'considers that only directory with the name provided in the WQL statement exists.
      Next

      '*****---------End of Script------------*****
    • I edited the reply to give more readibility to the VBS example...formatting in the comments it is not the best ;)
Please log in to comment
2
Although I'd recommend that you go for StockTraders advice, you could try the following:

ShellCommandTextReturn(cmd /c dir /S /B C:\msg.db | find "\ofoboarc\msg.db")

Note that it wont just search the root of the C-drive for "msg.db" but all subfolders for instances of the file (only tested on Windows 7 - may not work on other versions of Windows) and then pipe them over to the find-command, which will look for the exact ending ("\ofoboarc\msg.db"). As already mentioned, its not optimal and may result in delayed inventory or cause other problems, such as increased load on all machines that this custom inventory rule affects.
Answered 12/08/2014 by: AdamiteDK
White Belt

  • Flippin' brilliant, that works and doesn't take long on the inventory. Its a temporary thing anyway as we'll me migrating to Exchange next month.
Please log in to comment
Answer this question or Comment on this question for clarity