/build/static/layout/Breadcrumb_cap_w.png

Custom Inventory Rule

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

Answers (2)

Posted by: StockTrader 10 years ago
Red Belt
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------------*****

Comments:
  • Marco-will the scrip allow the use of those wildcards? - jmmctighe 10 years ago
    • 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------------***** - StockTrader 10 years ago
    • I edited the reply to give more readibility to the VBS example...formatting in the comments it is not the best ;) - StockTrader 10 years ago
Posted by: AdamiteDK 10 years ago
White Belt
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.

Comments:
  • 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. - jmmctighe 10 years ago
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ