K1000 (8.1) need a custom inventory rule CIR to find computers with a certain folder non-empty
We have a subset of machines that should never have files in the Downloads folder -- and if they do, something else is amiss. I'm looking to create a CIR (or another path, if you know of a better one!) to locate computers that have C:\Users\[SpecificUser]\Downloads NOT empty.
I've tried a CIR of FileExists(path), in this way:
FileExists(C:\Users\[SpecificUser]\Downloads\*.*
However this seems to return basically everything that inventories ( the user [SpecificUser] is actually built into most of the PCs on our system, but only rarely used).
Do you have any ideas? Maybe a script would handle this better?
Answers (1)
I tried this successfully in a command prompt but I didn't try it at as a CIR.
DirectoryExists(C:\Users\SpecificUser\Downloads) AND ShellCommandTextReturn(cmd /c dir /A C:\Users\SpecificUser\Downloads | find " 0 File(s) " > nul || echo Folder not empty)
Comments:
-
Or if you prefer powershell something like this
if ((gci C:\Users\SpecificUser\Downloads).count -ne 0) {"Folder not empty"} - flip1001 5 years ago -
I agree the above works in cmd but hasn't yet worked out as a CIR. It weirdly returned just like 6 clients, half of which had stuff in Downloads and the other half didn't. Still working on it. - agibbons 5 years ago
-
The dir /a command shows all files including hidden. Maybe the other half has hidden files? You can remove the /a parameter to only show regular files. - flip1001 5 years ago
-
Thanks! Good thought. I'll give it a shot -- I let the CIR roll for a day, which should have presented me with 100s of clients with stuff in downloads folders. It is strange that it did not. - agibbons 5 years ago